Skip to content

Commit 4eabe26

Browse files
Fix FP for invalid-name for TypedDicts (#10673)
1 parent ffb3320 commit 4eabe26

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false positive for ``invalid-name`` for ``TypedDict`` instances.
2+
3+
Closes #10672

pylint/checkers/base/name_checker/checker.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,14 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
490490
# Check classes (TypeVar's are classes so they need to be excluded first)
491491
elif isinstance(inferred_assign_type, nodes.ClassDef) or (
492492
isinstance(inferred_assign_type, bases.Instance)
493-
and "EnumMeta"
494-
in {
495-
ancestor.name
496-
for ancestor in cast(
497-
InferenceResult, inferred_assign_type
498-
).mro()
499-
}
493+
and {"EnumMeta", "TypedDict"}.intersection(
494+
{
495+
ancestor.name
496+
for ancestor in cast(
497+
InferenceResult, inferred_assign_type
498+
).mro()
499+
}
500+
)
500501
):
501502
self._check_name("class", node.name, node)
502503

tests/functional/i/invalid/invalid_name.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@ class FooBarSubclass(FooBar):
121121

122122
from enum import Enum
123123
Color = Enum('Color', [('RED', 1), ('GREEN', 2), ('BLUE', 3)])
124+
125+
126+
from typing import TypedDict
127+
MyExampleType = TypedDict("MyExampleType", {"some_field": str})

0 commit comments

Comments
 (0)