You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify logic with overriding callee in cases of TypedDict.get functions.
After poking around with this a bunch today I realized it would be much simplier to simply create
a context-specific Callable as opposed to attemping to hijack the rest of the typechecking.
The original implementation had problems in places, for example where a TypedDict had a List field.
A default empty list was not being coerced correctly.
p = PointSet(first_point=TaggedPoint(type='2d', x=42, y=1337))
480
-
p.get('first_point', 32).get('x', 0) # E: Some element of union has no attribute "get"
478
+
p.get('first_point', 32)# E: Argument 2 to "get" of "Mapping" has incompatible type "int"; expected "Union[TypedDict(type=str, x=int, y=int), Mapping]"
481
479
[builtins fixtures/dict.pyi]
482
480
483
481
[case testGetMethodOnList]
@@ -489,6 +487,14 @@ p = PointSet(points=[TaggedPoint(type='2d', x=42, y=1337)])
489
487
reveal_type(p.get('points', [])) # E: Revealed type is 'builtins.list[TypedDict(type=builtins.str, x=builtins.int, y=builtins.int, _fallback=__main__.TaggedPoint)]'
0 commit comments