10000 Accept compatible dict in place of TypedDict by pkch · Pull Request #3035 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Accept compatible dict in place of TypedDict #3035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add comment
  • Loading branch information
pkch committed Mar 21, 2017
commit c0c9bfe674355b8eb4f774a3e66e38af48528ebc
7 changes: 4 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,10 @@ def visit_dict_expr(self, e: DictExpr) -> Type:

Translate it into a call to dict(), with provisions for **expr.
"""
# if we find a DictExpr inside a context that expected TypedDict,
# we try to convert the dictionary into TypedDict
# we warn if they are not compatible or if we don't have enough info to verify
# if the dict literal doesn't match TypedDict, check_typeddict_call_with_dict reports
# an error, but returns the TypedDict type that matches the literal it found
# that would cause a second error when that TypedDict type is returned upstream
# to avoid the second error, we always return TypedDict type that was requested
if isinstance(self.type_context[-1], TypedDictType):
self.check_typeddict_call_with_dict(
callee=self.type_context[-1],
Expand Down
0