Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
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:
classFoo: ... classBar: def__delattr__(self, __name: str) ->None: ... f=Foo() b=Bar() delf.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)delb.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:
>>>importdecimal>>>c=decimal.Context() >>>c.prec=54>>>delc.precTraceback (mostrecentcalllast): File"<stdin>", line1, in<module>AttributeError: contextattributescannotbedeletedMaybe we could represent this by adding Context.__delattr__ back to the stub and giving it the signature def __delattr__(self, __name: str) -> NoReturn?