New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__conform__ shoud take the precedence over superclass adaptation #456

Closed
dvarrazzo opened this Issue Jul 15, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@dvarrazzo
Copy link
Member

dvarrazzo commented Jul 15, 2016

If an object declares itself conform, its rule should be applied. Currently (psycopg 2.6.2) the adapter first checks if a superclass is conform, then tries to use its rule. This makes impossible e.g. to just implement __conform__ on a tuple subclass and register_adapter() must be called.

In [1]: import psycopg2.extensions as ext

In [2]: class foo(tuple):
   ...:     def __conform__(self, proto):
   ...:         return self
   ...:     def getquoted(self):
   ...:         return 'bar'
   ...:     

In [6]: ext.adapt(foo((1,2,3))).getquoted()
Out[6]: '(1, 2, 3)'

The result should have been the same of:

In [7]: class foo2(object):
    def __conform__(self, proto):
        return self
    def getquoted(self):
        return 'bar'
   ...:     

In [8]: ext.adapt(foo2()).getquoted()
Out[8]: 'bar'

I'd like to fix it. There is a slight possibility to break some code... but I guess only for people who wrote their own __conform__ but they don't want to use it and use the builtin version? Unlikely huh?

Shall we fix it in psycopg3 or in 2.7?

@dvarrazzo dvarrazzo added this to the psycopg 2.7 milestone Jan 5, 2017

@dvarrazzo dvarrazzo closed this in 3fbff5d Feb 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment