Skip to content

Fix generic type expansion for attribute acces on class #2879

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

Closed
wants to merge 2 commits into from

Conversation

ilevkivskyi
Copy link
Member

Fixes #2878

The fix is very simple, expand_type_by_instance was applied only on access via instance (like C[int]().attr), now it will be also applied on access via class (like C[int].attr).

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 22, 2017

I don't think that the runtime semantics are correct for this -- see #2878 (comment).

@ilevkivskyi
Copy link
Member Author

@JukkaL I agree, see my comment in #2878
I am closing this now. Anyway there is no chance for this to go into 0.480
I will open another PR (if necessary) when we fix the runtime semantics.

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.
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.

Generic class atributes aren't fully instantiated
2 participants