KEMBAR78
Check duplicate bases when defining TypedDict by 97littleleaf11 · Pull Request #11485 · python/mypy · GitHub
Skip to content

Conversation

97littleleaf11
Copy link
Collaborator

@97littleleaf11 97littleleaf11 commented Nov 7, 2021

Description

Closes #3673

Adds a trivial for-loop and a helper set to check duplicates of typeddict_bases.

Test Plan

Adds a new test case testCannotCreateTypedDictWithDuplicateBases

typeddict_bases = []
typeddict_bases_set = set()
for expr in defn.base_type_exprs:
if (not isinstance(expr, RefExpr) or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there's two many nots here for this code to be readable. It looks like there are three cases: (1) the base class is TypedDict of some sort (expr.fullname in TPDICT_NAMES); (2) the base class is another TypedDict; (3) anything else, which produces an error. The code would be more readable if we covered those three cases in order, without any nots.

@JelleZijlstra JelleZijlstra merged commit 2907a4d into python:master Nov 8, 2021
@97littleleaf11 97littleleaf11 deleted the fix3673 branch November 8, 2021 05:18
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
### Description

Closes python#3673

Adds a trivial for-loop and a helper set to check duplicates of `typeddict_bases`.

## Test Plan

Adds a new test case `testCannotCreateTypedDictWithDuplicateBases`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate Base Class for TypedDict

2 participants