python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.44k stars 2.82k forks source link

Clean up kludges for handling metaclasses and Type[...] in check_op_reversible #5491

Open Michael0x2a opened 6 years ago

Michael0x2a commented 6 years ago

The current implementation for checking reversible operators contains two kludges that seem to be related to operators, metaclasses, and Type[...]

  1. This call to has_member feels like it ought to be unnecessary/redundant due to the following analyze_member_access -- but removing it causes pythoneval's OpMetaclassAccess test case to fail.

    (Note: if you remove just that call, you also need to add in a elif isinstance(member, AnyTyp): return None after calling analyze_member_access)

  2. If the reversible operators logic was unable to find a matching operator, it just tries calling check_call on the name directly to get back some generic error message. It seems as if this call ought to always return an error message, but sometimes it surprisingly will not. E.g. see the TypeTypeComparisonWorks tests in check-classes -- adding an assert local_errors.is_errors() causes that test case to crash.

    This feels related to the first TODO in some way -- either we're not handling operators + metaclasses + Type directly, or there are some weird shenanigans happening due to Any...

For additional context, see https://github.com/python/mypy/issues/5136 and https://github.com/python/mypy/pull/1806.

elazarg commented 6 years ago

I should work on this, if I will find the time.

Michael0x2a commented 6 years ago

@elazarg -- sounds good to me!

(I added myself mostly out of a sense of obligation, since the TODOs were a fallout of my operator refactors. But I also don't know when I'll find the time to do this, so feel free to tackle this whenever.)

elazarg commented 6 years ago

@Michael0x2a - sorry, I can't seem to find the time to do that.

Michael0x2a commented 6 years ago

@elazarg -- no worries, I'm also in the same boat.