-
| 
         Hi, I want to open a bug ticket in either  Variant AConsidering the following code: from typing import (
    Protocol,
    Type,
    List,
    runtime_checkable,
)
@runtime_checkable
class Plugin(Protocol):
    s: str
    def f(self):
        ...
class A:
    s = "Hello World"
    def f(self):
        print(A.s)
PLUGINS: List[Type[Plugin]] = [A, ]
if __name__ == '__main__':
    for p in PLUGINS:
        print(p.s)mypyAnalytics with  pyrightAnatytics with  Variant BOkay lets fix the pyright complaint regarding Variant A with the following code: from typing import (
    ClassVar,
    Protocol,
    Type,
    List,
    runtime_checkable,
)
@runtime_checkable
class Plugin(Protocol):
    s: ClassVar[str]
    def f(self):
        ...
class A:
    s = "Hello World"
    def f(self):
        print(A.s)
PLUGINS: List[Type[Plugin]] = [A, ]
if __name__ == '__main__':
    for p in PLUGINS:
        print(p.s)
mypyNow mypy complaints: pyrighteverythings fine here: QuestionWhat would you say, and why: Who did the better/correct conclusion and why?  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
| 
         The following change makes it work in both: @@ -16,7 +16,7 @@
 
 
 class A:
-    s = "Hello World"
+    s: ClassVar = "Hello World"
 
     def f(self):
         print(A.s)For some reason, mypy seems to think that  Also, every time you wrote pylint, you actually meant pyright :)  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         As @Akuli says, the difference in behaviour here appears to be due to the fact that pyright infers  As for which is correct: it's hard to say; it's a somewhat subjective question. It's likely that, in the majority of cases, pyright will be correct;   | 
  
Beta Was this translation helpful? Give feedback.
The following change makes it work in both:
For some reason, mypy seems to think that
s = "Hello World"creates an instance variable.Also, every time you wrote pylint, you actually meant pyright :)