Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10672.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false positive for ``invalid-name`` for ``TypedDict`` instances.

Closes #10672
15 changes: 8 additions & 7 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,14 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
# Check classes (TypeVar's are classes so they need to be excluded first)
elif isinstance(inferred_assign_type, nodes.ClassDef) or (
isinstance(inferred_assign_type, bases.Instance)
and "EnumMeta"
in {
ancestor.name
for ancestor in cast(
InferenceResult, inferred_assign_type
).mro()
}
and {"EnumMeta", "TypedDict"}.intersection(
{
ancestor.name
for ancestor in cast(
InferenceResult, inferred_assign_type
).mro()
}
)
):
self._check_name("class", node.name, node)

Expand Down
4 changes: 4 additions & 0 deletions tests/functional/i/invalid/invalid_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ class FooBarSubclass(FooBar):

from enum import Enum
Color = Enum('Color', [('RED', 1), ('GREEN', 2), ('BLUE', 3)])


from typing import TypedDict
MyExampleType = TypedDict("MyExampleType", {"some_field": str})
Loading