Created
February 23, 2020 23:36
-
-
Save PeterJCLaw/ca10117b4534dc6ba2c0b30bd2fc781a to your computer and use it in GitHub Desktop.
jedi handling of annotated non-ClassVar class attributes
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
| from typing import ClassVar | |
| class A: | |
| cls_attr = 1 | |
| cls_attr_comment = 2 # type: int | |
| cls_attr_classvar_comment = 2 # type: ClassVar[int] | |
| cls_attr_hint: int = 3 | |
| cls_attr_classvar_hint: ClassVar[int] = 3 | |
| @classmethod | |
| def func(cls) -> None: | |
| cls.cls_attr = 2 | |
| cls.cls_attr_comment = 3 | |
| cls.cls_attr_classvar_comment = 3 | |
| cls.cls_attr_hint = 4 | |
| cls.cls_attr_classvar_hint = 4 | |
| x = A.cls_attr | |
| x = A.cls_attr_comment | |
| x = A.cls_attr_classvar_comment | |
| x = A.cls_attr_hint | |
| x = A.cls_attr_classvar_hint | |
| A.cls_attr = 5 | |
| A.cls_attr_comment = 5 | |
| A.cls_attr_classvar_comment = 5 | |
| A.cls_attr_hint = 5 | |
| A.cls_attr_classvar_hint = 5 | |
| x = A().cls_attr | |
| x = A().cls_attr_comment | |
| x = A().cls_attr_classvar_comment | |
| x = A().cls_attr_hint | |
| x = A().cls_attr_classvar_hint | |
| A().cls_attr = 5 | |
| A().cls_attr_comment = 5 | |
| A().cls_attr_classvar_comment = 5 # mypy error: Cannot assign to class variable "cls_attr_classvar_comment" via instance | |
| A().cls_attr_hint = 5 | |
| A().cls_attr_classvar_hint = 5 # mypy error: Cannot assign to class variable "cls_attr_classvar_hint" via instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment