Josh Rosenberg added the comment:
The use case in question, simplified, was:
from functools import partial
class Foo:
Bar = othermodule.Bar
def __new__(cls, ...):
...
cls.Bar(...)
...
def bind_stuff(cls, *args, **kwargs):
cls.Bar = partial(Bar, *args, **kwargs)
Every time they created an instance of Foo, there would be a Foo.bind_stuff
call beforehand that fixed some settings they didn't want to make a part of
Foo's __new__ profile. And in fact, in practice, they were only binding the
same keyword args over and over, so they could have solved the problem by just
rebinding the base othermodule.Bar. I'm not defending this design, but from
what I can tell, it's a textbook example of where your patch would solve the
problem. cls.Bar has no instance variables assigned (hence no __dict__?), and
it's always functools.partial that's used, not some special variant.
A simple way to repro the fundamental problem they were experiencing is to just
wrap int a lot:
>>> for i in range(1001):
int = partial(int)
>>> int(5) # Kaboom! Which I assume your patch would prevent
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7830>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com