Skip to content

Should decimal.Context.__delattr__ be in the stub?#8504

@AlexWaygood

Description

@AlexWaygood

#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.spam

In 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: contextattributescannotbedeleted

Maybe 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions