Is there a way to mark in a Protocol that an attribute is a final instance attribute? Basically I would like for
class A:
def __init__(self, b; int):
self.b: Final[int] = b
To be a structural subtype of something like
class Y(Protocol):
b: Final[int] # Or something else
but in that case, b
is interpreted as a class attribute by type checkers.
I have also tried
class Y(Protocol):
@property
@abstractmethod
def b(self) -> int:
raise NotImplementedError
But at least Pylance does not allow consider A
as a structural subtype of Y
then.