Replies: 2 comments 2 replies
-
Currently this is not supported. There was a discussion about potentially adding Right now the most correct way is to have some attribute defined as such: class MyClass:
def __init__(self) -> None:
self.attr: int | None = None
def method(self) -> None:
self.attr = 1 # or whatever |
Beta Was this translation helpful? Give feedback.
1 reply
-
I'm curious what your desired behavior would be for such an attribute? Always emit an error/warning when accessing it, but also infer the resulting type as |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Cross posting from Stack Overflow:
How do I do a type hint for attribute that might not exist on the object in Python?
For example:
So, concretely:
Slots may not always be involved, but I can see wanting to do something similar when specifying a
Protocol
.Beta Was this translation helpful? Give feedback.
All reactions