-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
#8483 by @sobolevn deleted decimal.Context.__delattr__ from the stub, on the grounds that it had the exact same signature as builtins.object.__delattr__.
I think the rationale for this deletion was incorrect, as overriding __delattr__ on a subclass can cause a type checker to give that class special semantics, even if the signature of __delattr__ is identical to object.__delattr__. For example:
class Foo: ...
class Bar:
def __delattr__(self, __name: str) -> None: ...
f = Foo()
b = Bar()
del f.spam # mypy and pyright both emit an error here
# mypy emits an error here (it does not special-case __delattr__)
# pyright does *not* emit an error here (it special-cases __delattr__ to allow arbitrary deletions if __delattr__ is overridden)
del b.spamIn the specific case of Context.__delattr__, however, I'm not sure whether it should be present in the stub or not. This is the behaviour you get at runtime:
>>> import decimal
>>> c = decimal.Context()
>>> c.prec = 54
>>> del c.prec
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: context attributes cannot be deletedMaybe we could represent this by adding Context.__delattr__ back to the stub and giving it the signature def __delattr__(self, __name: str) -> NoReturn?
Metadata
Metadata
Assignees
Labels
No labels