[issue29270] super call in ctypes sub-class fails in 3.6

2020-01-18 Thread Clement Rouault
Clement Rouault added the comment: Hello, As this issue may never be fixed for python3.6. I wanted to post a solution to bypass the bug. It may be useful for the next person stumbling on this as I have. The __class__ closure is only created if a function use the word super(). This closure

[issue29270] super call in ctypes sub-class fails in 3.6

2019-10-25 Thread Clement Rouault
Clement Rouault added the comment: Hello, I have a Python2 project that relies heavily on ctypes and I cannot migrate this project to Python3 due to this bug. (I target 3.6) I have some experience with CPython and submitting patchs and I would like to know what I can do to help moving this

[issue29270] super call in ctypes sub-class fails in 3.6

2018-03-16 Thread Asdger Gdsfe
Asdger Gdsfe added the comment: Hey 3.6 is pretty old now so can we get this patch merged I'd really like this code to start working again, appreciate all your hard work! class Something(ctypes.c_ulong): def __repr__(self): return super(Something, self).value

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-26 Thread Nick Coghlan
Nick Coghlan added the comment: The scrapy case looks to just be the new metaclass constraint that's already covered in the "Porting to Python 3.6" guide: https://github.com/scrapy/scrapy/pull/2509/files The ctypes case is more complicated, as its actually *reusing* the same class namespace

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See also similar issue with scrapy: https://github.com/scrapy-plugins/scrapy-djangoitem/issues/18. -- ___ Python tracker

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-14 Thread Eryk Sun
Eryk Sun added the comment: Resolving this would be straightforward if we could use a subclass for the swapped type, but ctypes simple types behave differently for subclasses. A simple subclass doesn't automatically call the getfunc to get a converted value when returned as a function result,

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-14 Thread Nick Coghlan
Nick Coghlan added the comment: Yeah, re-using Python-level method objects in different types is genuinely invalid when combined with __class__ or zero-argument super(), as there's no way to make the __class__ closure refer to two different classes at runtime - it will always refer back to

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-14 Thread Eryk Sun
Eryk Sun added the comment: OK, this is completely broken and needs a more thoughtful solution than my simpleminded hack. Here's a practical example of the problem, tested in 3.5.2: class MyInt(ctypes.c_int): def __repr__(self): return super().__repr__() class

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-14 Thread Dave Jones
Dave Jones added the comment: I confess I'm going to have to read a bit more about Python internals before I can understand Eryk's analysis (this is my first encounter with "cell objects"), but many thanks for the rapid analysis and patch! I'm not too concerned about the state being broken

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-14 Thread Nick Coghlan
Nick Coghlan added the comment: Eryk's diagnosis sounds right to me, and the suggested patch will get this back to working as well as it did in Python 3.5. However, it's worth noting that that state itself was already broken when it comes to zero-argument super() support on the type

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-13 Thread Eryk Sun
Changes by Eryk Sun : -- stage: -> patch review ___ Python tracker ___ ___

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-13 Thread Eryk Sun
Eryk Sun added the comment: Here's a patch that deletes __classcell__ from the dict before calling type_new. -- keywords: +patch Added file: http://bugs.python.org/file46285/issue_29270_01.patch ___ Python tracker

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-13 Thread Eryk Sun
Eryk Sun added the comment: In 3.6, type_new in Objects/typeobject.c sets the __classcell__ in the dict if it's a cell object. It happens that CreateSwappedType in Modules/_ctypes/_ctypes.c re-uses the dict to create the swapped type (e.g. big endian), which in turn updates the __classcell__.

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-13 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- nosy: +ncoghlan, serhiy.storchaka versions: +Python 3.7 ___ Python tracker ___

[issue29270] super call in ctypes sub-class fails in 3.6

2017-01-13 Thread Dave Jones
New submission from Dave Jones: While investigating a bug report in one of my libraries (https://github.com/waveform80/picamera/issues/355) I've come across a behaviour that appears in Python 3.6 but not prior versions. Specifically, calling super() in a sub-class of a ctypes scalar type