-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
Currently there is some duplication around partial types:
- Logic in
try_infer_partial_generic_type_from_assignment()essentially duplicates the logic inlined incheck_assignment()forNonepartial types. These two probably can be refactored to the same method if we also updatehandle_partial_var_type()to not special-case partialNonetypes, and instead consistently return a partial type in lvalue context. - Logic in
try_infer_partial_type_from_indexed_assignment()duplicates that intry_infer_partial_type()(there is already a TODO item). This one can be refactored by either pushing the latter a bit down the call stack (closer tocheck_call()), or by generating a syntheticCallExprwith__setitem__and passing it totry_infer_partial_type().
The second item may be something to watch out when implementing support for these:
a = defaultdict(list)
a[0].append('yes')
b = {}
b.setdefault(0, []).append('yes')
c = defaultdict(set)
c[0].add('yes')
d = {}
d.setdefault(0, set()).add('yes')@JukkaL this is probably not something important, but maybe it makes sense to fix this while we are at it?