Roundup Robot added the comment:
New changeset 3d858f1eef54 by Benjamin Peterson in branch 'default':
hide the __class__ closure from the class body (#12370)
http://hg.python.org/cpython/rev/3d858f1eef54
--
___
Python tracker rep...@bugs.python.org
Benjamin Peterson added the comment:
Finally killed this one properly.
--
resolution: - fixed
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
Daniel Urban added the comment:
Thanks for the review!
Nick, the example with Outer, InnerParent and InnerChild still works (the
evaluation happens before we enter the new scope).
Of course you're all right about __args__ and __kw__. I'll try to find a way to
hide them.
--
stage:
Eric Snow added the comment:
I agree with Benjamin re: __args__ and __kw__.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Nick Coghlan added the comment:
From a quick scan of the patch, I suspect the current implementation will also
break this code:
class Outer:
class InnerParent:
pass
class InnerChild(InnerParent):
pass
The evaluation of the other args to build_class needs to happen before
Daniel Urban added the comment:
I tried to implement Nick's idea with the separate scope for __class__. It
seems to work, I'm attaching a patch. The patch basically causes the following
class statement:
class C(A, B, metaclass=meta):
def f(self):
return __class__
To be compiled
Benjamin Peterson added the comment:
The ability to close over __args__ and __kw__ in class methods is undesirable.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
Nick Coghlan added the comment:
Carsten: emulating __class__ is necessary to implement proxy types (and similar
utilities like mock objects) correctly. The difference between x.__class__ is
that proxies can remap it to the type of the referent, while type(x) will
always report the real class
Carsten Klein added the comment:
The change was introduced in r30 (Python/symtable.c @ near where it reads /*
Special-case super: it counts as a use of __class__ */)
which now enforces that a class that calls super on init will have the correct
class information present.
I do not think that
Mark Shannon added the comment:
There seems to be an ongoing confusion about scopes on this thread.
The __class__ variable used by super() is a non-local variable in the scope of
any function using super(), whereas the __class__ used to define the type of an
object is a class attribute like
Nick Coghlan added the comment:
OK, I think I have a way to fix this that will actually *reduce* the level of
special casing needed in the compiler.
Specifically, I think we may be able to make the class statement emit *two*
scopes, rather than the current one. The outer scope would be
Eric Snow added the comment:
Wouldn't the following also start working (currently a NameError)?
class X:
def f(self):
print(f.__qualname__)
def g(self):
f(None)
X().f()
X().g()
How about this[1] (also currently a NameError):
class Outer:
class
Eric Snow added the comment:
Actually, that second would still not work (it would have to pass through the
non-lexical inner scope that Nick mentioned). Is that also the case for the
first one?
--
___
Python tracker rep...@bugs.python.org
Nick Coghlan added the comment:
Yep. The only name in the new scope would be __class__. Everything else,
including method names, should remain invisible from method bodies. I'm not
100% sure it will work as we want, but that's because I'm not sure if we
can avoid causing a semantic change for
Eric Snow added the comment:
sounds like it would be worth a shot
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list
Changes by Chris Rebert pyb...@rebertia.com:
--
nosy: +cvrebert
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list
Roundup Robot devn...@psf.upfronthosting.co.za added the comment:
New changeset 96ab78ef82a7 by Nick Coghlan in branch 'default':
Close #14857: fix regression in references to PEP 3135 implicit __class__
closure variable. Reopens issue #12370, but also updates unittest.mock to
workaround that
Nick Coghlan ncogh...@gmail.com added the comment:
As the checkin message says, this is once again a problem on trunk. The
relevant test is still in place in test_super.py, I just marked it as an
expected failure.
unittest.mock is currently avoiding the problem via the _safe_super = super
Changes by Meador Inge mead...@gmail.com:
--
nosy: +meador.inge
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list
Changes by Mark Shannon m...@hotpy.org:
--
nosy: +Mark.Shannon
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list
Changes by Daniel Urban urban.dani...@gmail.com:
--
nosy: +durban
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:
--
nosy: +Arfrever
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
Nick Coghlan ncogh...@gmail.com added the comment:
And to record the workaround for 3.1 and 3.2 (courtesy of Michael):
Adding a _super = super alias at the module level and using the Python 2.x
style long form invocation on _super() in affected methods will avoid the
compiler games played
Barry A. Warsaw ba...@python.org added the comment:
That work around seems ugly. Why not back port the fix? It doesn't seem like
it could break anything and it's not even arguably a new feature, right?
--
nosy: +barry
___
Python tracker
Benjamin Peterson benja...@python.org added the comment:
One reason is that it bumps the pyc magic number.
--
nosy: +benjamin.peterson
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
Barry A. Warsaw ba...@python.org added the comment:
Ah okay, I didn't see that in the changeset.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
New submission from Michael Foord mich...@voidspace.org.uk:
In Python 3 the following code prints False because the use of super() has
caused the __class__ descriptor to be omitted from the class namespace. Remove
the use of super and it prints True.
class X(object):
def
Changes by Alex Gaynor alex.gay...@gmail.com:
--
nosy: +alex
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12370
___
___
Python-bugs-list mailing
Roundup Robot devnull@devnull added the comment:
New changeset 2d62ee4e7d98 by Benjamin Peterson in branch 'default':
use a invalid name for the __class__ closure for super() (closes #12370)
http://hg.python.org/cpython/rev/2d62ee4e7d98
--
nosy: +python-dev
resolution: - fixed
stage:
29 matches
Mail list logo