Basic misunderstanding on object creation

Terry Reedy tjreedy at udel.edu
Wed May 13 13:13:39 EDT 2015


On 5/13/2015 12:36 PM, Terry Reedy wrote:
> On 5/13/2015 9:25 AM, andrew cooke wrote:
>
>> The following code worked on Python 3.2, but no longer works in 3.4.
>
> Bugfixes break code that depends on buggy behavior. See
> https://bugs.python.org/issue1683368
> Your code also fails in 2.7.9 if you inherit Foo from object.
> The exact error messages changed for 3.4 in
> https://bugs.python.org/issue7963
>
>  > Did something change,
>
> Obviously yes.
>
>  > or have I always been doing something dumb?
>
> You were depending on behavior of object that Guido decided was buggy.
>
> I found the tracker issue by looking for 'object' in the Core and
> Builtins sections of the changelog one can access from What's New, first
> paragraph (using Highlight All in Firefox).
>
>>>>> class Foo:
>> ...     def __new__(cls, *args, **kargs):
>> ...         print('new', args, kargs)
>> ...         super().__new__(cls, *args, **kargs)

I forgot to memtion that it is intended that one remove arguments that 
are specific to a class before passing them on to super. All arguments 
should be consumed (removed) somewhere in the chain before reaching 
object.  The bug that was fixed was not raising when not all args were 
consumed. As other showed, your code works properly in all versions when 
you do so by only passing on cls.

-- 
Terry Jan Reedy




More information about the Python-list mailing list