Fix generic type expansion for attribute acces on class#2879
Closed
ilevkivskyi wants to merge 2 commits intopython:masterfrom
Closed
Fix generic type expansion for attribute acces on class#2879ilevkivskyi wants to merge 2 commits intopython:masterfrom
ilevkivskyi wants to merge 2 commits intopython:masterfrom
Conversation
Collaborator
|
I don't think that the runtime semantics are correct for this -- see #2878 (comment). |
Member
Author
JukkaL
pushed a commit
that referenced
this pull request
Mar 9, 2017
Implements ClassVar introduced in PEP 526. Resolves #2771, #2879. * Support annotating class attributes with ClassVar[...]. * Prohibit ClassVar annotations outside class bodies (regular variable annotations, function and method signatures). * Prohibit assignments to class variables accessed from instances (including assignments on self). * Add checks for overriding class variables with instance variables and vice versa when subclassing. * Prohibit ClassVars nested inside other types. * Add is_classvar flag to Var. * Add nesting_level attribute to TypeAnalyser and use it inside helper methods anal_type and anal_array. Move analyzing implicit TupleTypes from SemanticAnalyzer to TypeAnalyser. * Analyze ClassVar[T] as T and bare ClassVar as Any. * Prohibit generic ClassVars and accessing generic instance variables via class (see #2878 comments). * Add types.get_type_vars helper, which returns all type variables present in analyzed type, similar to TypeAnalyser.get_type_var_names.
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.
Fixes #2878
The fix is very simple,
expand_type_by_instancewas applied only on access via instance (likeC[int]().attr), now it will be also applied on access via class (likeC[int].attr).