kio
kio copied to clipboard
refactor: Improve typing of classify_field()
This addresses a part of the code base that had a lot of type ignores. This was due to how the return type of the classify_field() function did not maintain the relationship of its two values, and not having precise enough information for the case when the inner type is a subtype of Entity.
By introducing specialized types for each four cases in conjunction with a union return type, mypy is able to much better keep track of the relationship that a field classified as an "entity field" must carry a type that is a subtype of Entity.
As can be seen in the diff, test_introspect.py is the only changed test module, this only has fallout on the internal introspection API. The improvement and intent of this commit is to reduce the amount of type ignores in get_field_reader() and get_field_writer().
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
c99b28f) to head (049d879).
Additional details and impacted files
@@ Coverage Diff @@
## main #132 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 822 852 +30
Branches 132 141 +9
=========================================
+ Hits 822 852 +30
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.