stubtest: ignore setattr and delattr inherited from object#18325
stubtest: ignore setattr and delattr inherited from object#18325hauntsaninja merged 3 commits intopython:masterfrom
Conversation
__setattr__ and __delattr__ from object are special cased by type checkers, so defining them on an inheriting class, even with the same signature, has a different meaning.
|
I also took the opportunity to make the style of the conditionals introduced by #18314 match. |
|
I'll note additionally that I can see arguments both for and against this change. I'm curious to see what other people think. In favor is that it draws attention to the special nature of overriding |
hauntsaninja
left a comment
There was a problem hiding this comment.
Seems like a good change to me!
Setting runtime_attr = MISSING gets a little dicey.
I think it's fine in this case because of IGNORABLE_CLASS_DUNDERS, but maybe we should make verify_none simply return if runtime is missing (probably should rename it to verify_missing too)
|
Oh, interesting. I thought that would be correct because of It looks like we hit |
hauntsaninja
left a comment
There was a problem hiding this comment.
Yup exactly!
I'll leave open for a few days in case anyone else has opinions
__setattr__and__delattr__from object are special cased by type checkers, so defining them on an inheriting class, even with the same signature, has a different meaning.This one is very similar to #18314.
Typeshed has this allowlist entry:
multiprocessing.(dummy|managers).Namespace.__[gs]etattr__ # Any field can be set on NamespaceI was looking into this after I noticed that
Namespace.__setattr__didn't appear in my local stubtest results. The reason is that it's inherited from object, butobject.__setattr__has this note in typeshed:That lead me to python/typeshed#7385, which discusses how type checkers ignore
object.__setattr__andobject.__delattr__as a matter of practicality. In that light, I think that stubtest should also ignore these methods when inherited from object at runtime, and flag their existence in the stubs when runtime doesn't have a custom version.This change generates these new errors in typeshed:
It would also create new errors for
multiprocessing.dummy.Namespace.__setattr__andmultiprocessing.managers.Namespace.__setattr__, but these are already on the allowlist.