Closed
Description
There are bunch of places where we duplicate some parts of code for special logic in member access (such as properties, class methods, descriptors, __getattr__()
, etc):
- The
checkmember.py
itself - Override checks for variables
- Override checks for methods
- Multiple inheritance checks
- Checks for special methods via
check_op()
andhas_member()
- Protocol implementation check
Here are some issues that will be solved (or significantly simplified) by refactoring this to go through the same place (probably checkmember.py
):
- Mypy disallows overriding an attribute with a property #4125
- Overriding definition such as type alias in a subclass causes a crash #5425
- Refactor operator method access and protocol checks to use checkmember.py #5136
- Refactor common code in analyze_member_access and find_member #3832
- Overriding method with a property results in a false negative #7565
- mypy false positive with custom property descriptors #7153
- Decorated method type-incompatibility with superclass #5836
- Custom property/descriptor and base classes #5803
- Clean up kludges for handling metaclasses and Type[...] in check_op_reversible #5491
- Protocols don't support descriptors #5481
Also I think having member access cleaned-up, centralized, and documented will open the way to finally solving #708 (currently the oldest high priority issue), and to having general support for descriptor protocol (for historical reasons, several things like properties are supported via some special-casing).