Closed PietroPasotti closed 1 day ago
@paulomach can you show what typing error(s) you're seeing by the way? pyright seems to be fine with subclasses
Also decorating the superclass instead seems to be good.
Hi @PietroPasotti , the following:
from typing import Type
class A:
def foo(self):
print("original foo")
def decorator():
# def _decorator(cls): <- untyped arg
def _decorator(cls: Type[A]):
setattr(cls, "_decorated", True)
return cls
return _decorator
@decorator()
class B(A):
def foo(self):
print("foo")
def bar(self):
print("bar")
if __name__ == "__main__":
b = B()
if b._decorated:
print("b is decorated")
b.foo()
b.bar() # here pyright tells "bar" is unknown. Removing Type on _decorator allows correct resolution
I'm all for type annotations, but for charms that implement some other inheritance, this breaks LSP(pyright) goodies
Originally posted by @paulomach in https://github.com/canonical/tempo-k8s-operator/issues/128#issuecomment-2183619281