Skip to content
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

plone.reload and super() #1

Open
hannosch opened this issue Apr 3, 2011 · 4 comments
Open

plone.reload and super() #1

hannosch opened this issue Apr 3, 2011 · 4 comments

Comments

@hannosch
Copy link
Contributor

hannosch commented Apr 3, 2011

MJ told me at some point that methods using super() aren't reloaded properly.

@d-maurer
Copy link

The reason: for methods using super, Python adds a "closure variable" with name __class__. The _closure_changed check detects that the closures are different (one contains the old, the other the new class) and therefore, the method is not updated in place but overridden. The new method definition contains the wrong class reference and therefore the isinstance check of super fails.

Recommendation: replace the simplistic _closure_changed function by something more intelligent: it should ignore for the comparison cells in the closure that correspond to the __class__ cell. To be able to do this, it must get the full function and not only its closures as parameter. <func>.__code__.co_freevars gives in modern Python versions the names for the closure cells. This way, the check can ignore differences for the __class__ cell.

@d-maurer
Copy link

d-maurer commented Mar 2, 2019

Note: I have just released dm.plonepatches.reload with 2 patches to improve on plone.reload. Under Python 3, the patches allow proper handling of super (this issue) and classmethod (--> #11 ). In addition, for Python 2 and 3, they allow a reload of top level modules (--> #10 ) and the update in place of simple decorated functions.

dm.plonepatches.reload is released under the GPL. Thus, you can take inspiration or use pieces of code from it without fear to infringe my intellectual property rights.

@pbauer
Copy link
Member

pbauer commented Mar 18, 2021

@d-maurer please make a pull-request with your fixes

@d-maurer
Copy link

d-maurer commented Mar 18, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants