Skip to content

Commit

Permalink
Fixed recent regression in the synthesized TypedDict get method, wh…
Browse files Browse the repository at this point in the history
…ich resulted in a false positive error when using strict mode. This addresses #5452.
  • Loading branch information
msfterictraut committed Jul 11, 2023
1 parent c41bc9c commit 1e03e38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions packages/pyright-internal/src/analyzer/typedDicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,7 @@ export function synthesizeTypedDictClassMethods(
)
);
getOverloads.push(
createGetMethod(
literalStringInstance,
/* valueType */ UnknownType.create(),
/* includeDefault */ true
)
createGetMethod(literalStringInstance, /* valueType */ AnyType.create(), /* includeDefault */ true)
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/typedDict12.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def func1(a: TD3, b: TD4, c: C, s: str) -> int | None:
a3 = a.get("bar")
reveal_type(a3, expected_text="None")
a4 = a.get("bar", 1.0)
reveal_type(a4, expected_text="Unknown | float")
reveal_type(a4, expected_text="Any | float")
a5 = a.get("baz")
reveal_type(a5, expected_text="int | None")
a6 = a.get("baz", 1.0)
Expand Down Expand Up @@ -94,7 +94,7 @@ def func1(a: TD3, b: TD4, c: C, s: str) -> int | None:
c3 = c.get("bar")
reveal_type(c3, expected_text="str | None")
c4 = c.get("bar", 1.0)
reveal_type(c4, expected_text="Unknown | float | str")
reveal_type(c4, expected_text="Any | float | str")
c5 = c.get("baz")
reveal_type(c5, expected_text="int | Any | None")
c6 = c.get("baz", 1.0)
Expand Down

0 comments on commit 1e03e38

Please sign in to comment.