Repository navigation
Store nested classes themselves on the outer class (#875) - #907
Open
HoneyBearTech wants to merge 1 commit into
Open
HoneyBearTech wants to merge 1 commit into
HoneyBearTech wants to merge 1 commit into
Conversation
…#875) A class defined inside a class body was left on the outer class as the internal EvalLocalVar placeholder instead of the class itself. So after the outer class was created, Outer.Inner | None raised the same TypeError as in custom-components#875, and type(Outer.Inner()) is Outer.Inner was False. Before the outer class is created, replace each defined EvalLocalVar in a plain dict class namespace with the value it holds. The placeholders themselves are left alone, so methods that read the nested class by its bare name keep working as before. A class namespace that isn't a plain dict, such as a mapping returned by a custom metaclass __prepare__, is left as it is. Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #875
What was broken
A class defined inside another class's body stayed on the outer class as the internal
EvalLocalVarplaceholder, not the class itself. So once the outer class was built,Outer.Innerbehaved differently from Python:This is the same error as #875, for a class nested in another class.
What I changed
Just before the outer class is created, each defined
EvalLocalVarin its namespace is replaced by the value it holds. The placeholder objects themselves aren't changed, so methods that use the nested class by its bare name keep working as before. A class namespace that isn't a plaindict, such as one returned by a custom metaclass__prepare__, is left as it is.Testing
tests/test_unit_eval.py, compared against CPython:Outer.Inner | None, at module level and in another class's annotations;type(Outer.Inner()) is Outer.Innerandisinstance;__prepare__namespaces.Note
#902 and #906 also change
ast_classdef, in different lines. Whichever merges later may need a small rebase; I'm happy to do it.