From 62fe1771ccc54a0805b82aeac8e51ca83aede031 Mon Sep 17 00:00:00 2001 From: Winston H <56998716+winstxnhdw@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:41:06 +0800 Subject: [PATCH 1/2] fix: exempt `TypedDict` from `typing_extensions` --- pylint/checkers/design_analysis.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index f8c1d5c6c9..da726d1b0d 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -87,6 +87,7 @@ DATACLASS_IMPORT = "dataclasses" TYPING_NAMEDTUPLE = "typing.NamedTuple" TYPING_TYPEDDICT = "typing.TypedDict" +TYPING_EXTENSIONS_TYPEDDICT = "typing_extensions.TypedDict" # Set of stdlib classes to ignore when calculating number of ancestors STDLIB_CLASSES_IGNORE_ANCESTOR = frozenset( @@ -168,6 +169,7 @@ "typing.Sized", TYPING_NAMEDTUPLE, TYPING_TYPEDDICT, + TYPING_EXTENSIONS_TYPEDDICT ) ) @@ -179,7 +181,7 @@ def _is_exempt_from_public_methods(node: astroid.ClassDef) -> bool: for ancestor in node.ancestors(): if is_enum(ancestor): return True - if ancestor.qname() in (TYPING_NAMEDTUPLE, TYPING_TYPEDDICT): + if ancestor.qname() in (TYPING_NAMEDTUPLE, TYPING_TYPEDDICT, TYPING_EXTENSIONS_TYPEDDICT): return True # Or if it's a dataclass From b6cc6b35f3d59feee9c1be78e250f87842db2851 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:45:15 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pylint/checkers/design_analysis.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index da726d1b0d..cb64e0a9ba 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -169,7 +169,7 @@ "typing.Sized", TYPING_NAMEDTUPLE, TYPING_TYPEDDICT, - TYPING_EXTENSIONS_TYPEDDICT + TYPING_EXTENSIONS_TYPEDDICT, ) ) @@ -181,7 +181,11 @@ def _is_exempt_from_public_methods(node: astroid.ClassDef) -> bool: for ancestor in node.ancestors(): if is_enum(ancestor): return True - if ancestor.qname() in (TYPING_NAMEDTUPLE, TYPING_TYPEDDICT, TYPING_EXTENSIONS_TYPEDDICT): + if ancestor.qname() in ( + TYPING_NAMEDTUPLE, + TYPING_TYPEDDICT, + TYPING_EXTENSIONS_TYPEDDICT, + ): return True # Or if it's a dataclass