Closed jakkdl closed 1 year ago
Updated strategy as per @Zac-HD's suggestion and moved the logic down into leave_Param
. Still leaving as draft for now, although it's mostly finished.
The tests could be more ambitious if you want, since this covers far from all possible branches of guess_type_from_argname
(I guess that's what I end up doing by default when there's no coverage to keep me accountable :sweat_smile: )
Wrote logic for inferring simple container types, removed speculative matches, and added a lot of tests.
I also modified _annotate_param
to handle recursive generics - so it can now do Optional[List[int]]
etc.
Pushed a commit with minor changes from the above review
Moved both the constants and the function (since it as well is ~100 lines) into autotyping.guess_type_from_argname.py
. Changed guess_type_from_argname
to return a string instead of NamedParam
to avoid a circular import, and did a minor restructure in leave_Param
to avoid duplicate code calling guess_type_from_argname
.
Also squashed the commits.
Fixes #46 leaving as draft until specs has been finalized, i.e. how to handle common names with default value of
None
and the extent of common names to use for inferring.I decided that the least intrusive way of implementing was to hijack
annotate_optionals
[andannotate_named_params
, so I just append the guessed names to those lists. I at first considered implementing this inleave_Param
, and could move back there if that's preferred. It took me a while to parseleave_Param
and I started adding comments for myself, and figured I might as well leave them.