Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow instances of a class to access inner class definitions on that class. - #3636

Merged
gvanrossum merged 2 commits into
python:masterfrom
rowillia:fix_3635
Jun 30, 2017
Merged

Allow instances of a class to access inner class definitions on that class.#3636
gvanrossum merged 2 commits into
python:masterfrom
rowillia:fix_3635

Conversation

@rowillia

Copy link
Copy Markdown
Contributor

This fixes #3635

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution is a bit hacky, since it seems to me such things should be done in semanal.py, but maybe there will be other problems, so that I am fine with this.

@emmatyping

Copy link
Copy Markdown
Member

I too had similar concerns on further consideration, however, I cannot think of another case where an inner class might cause issues like this. Though I suppose not considering uses of inner classes is exactly what caused the bug. I think it would be better to fix semanal, as it would avoid potential future issues. Also I don't like the idea of mypy "lying" about the type, as it makes the code harder to understand unless you are familiar with this hack.


reveal_type(Foo.Meta.name) # E: Revealed type is 'builtins.str'
reveal_type(Foo().meta.name) # E: Revealed type is 'builtins.str'
reveal_type(Foo().Meta.name) # E: Revealed type is 'builtins.str'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not test Foo.meta.name too?

And what will the types of Foo.Meta, Foo().Meta, Foo.meta and Foo().meta be revealed to be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! Added those tests in.

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

Successfully merging this pull request may close these issues.

Error when accessing attribute of inner class

4 participants