You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Changed strict-equality behavior with dict/Mapping #16340
I'm not sure if the new behavior is better or not, but I suspect that the change in behavior may have been an unintended consequence of #16237, so it seems worth investigating what is going on.
This is actually intentional. For my len() PR I needed to disable the len() check if a tuple subclass has a custom (i.e. user-defined) __len__() (and/or a user-defined __bool__() for cases like assert some_tuple). But then it turned out the existing helper custom_special_method() didn't work, because it considered special methods defined in typing as user-defined (it only allowed builtins as not user-defined), and tuple gets its __len__() from typing. But also it turns out dict gets its __eq__() from typing as well, so we actually never checked unsafe overlap for dictionaries/mappings (because we always considered equality as user-defined there).
FWIW I think the new behavior is consistent with how we handle e.g. lists etc where we get
Activity
ilevkivskyi commentedon Oct 27, 2023
This is actually intentional. For my
len()PR I needed to disable thelen()check if a tuple subclass has a custom (i.e. user-defined)__len__()(and/or a user-defined__bool__()for cases likeassert some_tuple). But then it turned out the existing helpercustom_special_method()didn't work, because it considered special methods defined intypingas user-defined (it only allowedbuiltinsas not user-defined), andtuplegets its__len__()fromtyping. But also it turns outdictgets its__eq__()fromtypingas well, so we actually never checked unsafe overlap for dictionaries/mappings (because we always considered equality as user-defined there).FWIW I think the new behavior is consistent with how we handle e.g. lists etc where we get
I propose closing this.
JukkaL commentedon Oct 27, 2023
Makes sense! Thanks for looking into this.