Skip to content

ClassVar in protocols: mypy and pyright have different opinions #1056

Answered by Akuli
tvannahl asked this question in Q&A
Discussion options

You must be logged in to vote

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 s = "Hello World" creates an instance variable.

Also, every time you wrote pylint, you actually meant pyright :)

Replies: 2 comments 15 replies

Comment options

You must be logged in to vote
4 replies
@erictraut
Comment options

@tvannahl
Comment options

@carljm
Comment options

carljm Feb 4, 2022
Collaborator

@tvannahl
Comment options

Answer selected by tvannahl
Comment options

You must be logged in to vote
11 replies
@carljm
Comment options

carljm Feb 4, 2022
Collaborator

@AlexWaygood
Comment options

@erictraut
Comment options

@tvannahl
Comment options

@carljm
Comment options

carljm Feb 4, 2022
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants