]> git.ipfire.org Git - thirdparty/psycopg.git/commit
Define better registering, importing, subclassing adapters.
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Jan 2021 13:52:27 +0000 (14:52 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 8 Jan 2021 01:32:29 +0000 (02:32 +0100)
commit991cec5ac6790ae09ae2ff91d4147d71df48ddf5
treec842a853a62c27f1f8c5ad5c92e5b9aa103727f7
parent282c1841419b36519ec6b2d79f1ddc2e4b820d53
Define better registering, importing, subclassing adapters.

- The C dumpers cannot be subclassed. Subclassing from Python makes
  difficult to use the c fast path, unless doing relatively expensive
  checks.

- C optimised classes are chosen on registration. The types module only
  exposes the Python objects, so they can be documented and subclassed.

Override adapter in the respective type modules

This way they are properly exposed to the rest of the Python code.

Note that it will need some trickery to be able to subclass them in
Python: overridden adapter will need the C fast path bypassed if
subclassing is detected.

Export C int subclasses dumpers to Python

Added guards to allow subclassing C adapters

Not sure this is the way to go though. Subclassing might be a rare
enough case to just make the classes final.

The check is implemented at instance level: it would be more efficient
to implement it at class level, however I don't know how to store class
attribute or implement metaclasses in Cython.

Don't make C types subclassable

C types are no more exposed in types, so they won't get subclassed by
final users.

Checking for subclass in adaptation is expensive, so I'd rather not do
it.

Check if a class has a matching optimised class (with the same name) at
registration time.
psycopg3/psycopg3/__init__.py
psycopg3/psycopg3/adapt.py
psycopg3_c/psycopg3_c/_psycopg3.pyi
psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx
psycopg3_c/psycopg3_c/types/numeric.pyx
psycopg3_c/psycopg3_c/types/singletons.pyx
psycopg3_c/psycopg3_c/types/text.pyx
tests/test_adapt.py
tests/test_copy.py