From 09f9e350a333daab6641c9c8bdff108694aa47b3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 26 Mar 2022 00:45:01 +0100 Subject: [PATCH 1/2] Loosen TypeVar name pattern --- ChangeLog | 5 +++++ pylint/checkers/base/name_checker/checker.py | 2 +- .../t/typevar_naming_style_default.py | 3 +++ .../t/typevar_naming_style_default.txt | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 895325445e..49a1b02106 100644 --- a/ChangeLog +++ b/ChangeLog @@ -46,6 +46,11 @@ Release date: TBA Closes #2793 +* Loosen TypeVar default name pattern a bit to allow names with multiple uppercase + characters. E.g. ``HVACModeT`` or ``IPAddressT``. + + Closes #5981 + * Fixed false positive for ``unused-argument`` when a ``nonlocal`` name is used in a nested function that is returned without being called by its parent. diff --git a/pylint/checkers/base/name_checker/checker.py b/pylint/checkers/base/name_checker/checker.py index 5943640c4b..68adadc3c6 100644 --- a/pylint/checkers/base/name_checker/checker.py +++ b/pylint/checkers/base/name_checker/checker.py @@ -26,7 +26,7 @@ # Default patterns for name types that do not have styles DEFAULT_PATTERNS = { "typevar": re.compile( - r"^_{0,2}(?:[^\W\da-z_]+|(?:[^\W\da-z_][^\WA-Z_]+)+T?(? Date: Sat, 26 Mar 2022 01:13:26 +0100 Subject: [PATCH 2/2] Update docs --- doc/user_guide/options.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/user_guide/options.rst b/doc/user_guide/options.rst index 6e1535e249..d89e5e988b 100644 --- a/doc/user_guide/options.rst +++ b/doc/user_guide/options.rst @@ -95,7 +95,8 @@ The following type of names are checked with a predefined pattern: +--------------------+---------------------------------------------------+------------------------------------------------------------+ | Name type | Good names | Bad names | +====================+===================================================+============================================================+ -| ``typevar`` |`T`, `_CallableT`, `_T_co`, `AnyStr`, `DeviceTypeT`| `DICT_T`, `CALLABLE_T`, `ENUM_T`, `DeviceType`, `_StrType` | +| ``typevar`` | ``T``, ``_CallableT``, ``_T_co``, ``AnyStr``, | ``DICT_T``, ``CALLABLE_T``, ``ENUM_T``, ``DeviceType``, | +| | ``DeviceTypeT``, ``IPAddressT`` | ``_StrType`` | +--------------------+---------------------------------------------------+------------------------------------------------------------+ Custom regular expressions