summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-03-28 22:55:13 +0200
committerGitHub <noreply@github.com>2023-03-28 22:55:13 +0200
commit4e11693a411433cb03b07fc3a04f2e4151280953 (patch)
treeb868da27bd7e21f22e9ff93f7ea6ee097ee21857
parentd429822d56c392b4be914f94d55807b55efbd705 (diff)
downloadpylint-git-4e11693a411433cb03b07fc3a04f2e4151280953.tar.gz
[Backport maintenance/2.17.x] Allow integers in TypeAlias names. (#8507)
Co-authored-by: Stephane Odul <1504511+sodul@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
-rw-r--r--doc/data/messages/i/invalid-name/details.rst10
-rw-r--r--doc/whatsnew/fragments/8485.false_positive5
-rw-r--r--pylint/checkers/base/name_checker/checker.py4
-rw-r--r--tests/functional/t/typealias_naming_style_default.py3
-rw-r--r--tests/functional/t/typealias_naming_style_default.txt21
5 files changed, 27 insertions, 16 deletions
diff --git a/doc/data/messages/i/invalid-name/details.rst b/doc/data/messages/i/invalid-name/details.rst
index ad155bc14..7e2090158 100644
--- a/doc/data/messages/i/invalid-name/details.rst
+++ b/doc/data/messages/i/invalid-name/details.rst
@@ -88,11 +88,11 @@ The following type of names are checked with a predefined pattern:
| ``typevar`` | ``T``, ``_CallableT``, ``_T_co``, ``AnyStr``, | ``DICT_T``, ``CALLABLE_T``, ``ENUM_T``, ``DeviceType``, |
| | ``DeviceTypeT``, ``IPAddressT`` | ``_StrType`` |
+--------------------+-------------------------------------------------------+------------------------------------------------------------+
-| ``typealias`` | ``GoodName``, ``_GoodName``, ``IPAddressType`` and | ``BadNameT``, ``badName``, ``TBadName``, ``TypeBadName`` |
-| | other PascalCase variants that don't start with ``T``| |
-| | or ``Type``. This is to distinguish them from | |
-| | ``typevars``. Note that ``TopName`` is allowed but | |
-| | ``TTopName`` isn't. | |
+| ``typealias`` | ``GoodName``, ``_GoodName``, ``IPAddressType``, | ``BadNameT``, ``badName``, ``TBadName``, ``TypeBadName``, |
+| | ``GoodName2`` and other PascalCase variants that | ``_1BadName`` |
+| | don't start with ``T`` or ``Type``. This is to | |
+| | distinguish them from ``typevars``. Note that | |
+| | ``TopName`` is allowed but ``TTopName`` isn't. | |
+--------------------+-------------------------------------------------------+------------------------------------------------------------+
Custom regular expressions
diff --git a/doc/whatsnew/fragments/8485.false_positive b/doc/whatsnew/fragments/8485.false_positive
new file mode 100644
index 000000000..8eac08b95
--- /dev/null
+++ b/doc/whatsnew/fragments/8485.false_positive
@@ -0,0 +1,5 @@
+``invalid-name`` now allows for integers in ``typealias`` names:
+- now valid: ``Good2Name``, ``GoodName2``.
+- still invalid: ``_1BadName``.
+
+Closes #8485
diff --git a/pylint/checkers/base/name_checker/checker.py b/pylint/checkers/base/name_checker/checker.py
index 616067d1f..c2b615a48 100644
--- a/pylint/checkers/base/name_checker/checker.py
+++ b/pylint/checkers/base/name_checker/checker.py
@@ -41,7 +41,9 @@ DEFAULT_PATTERNS = {
"typevar": re.compile(
r"^_{0,2}(?!T[A-Z])(?:[A-Z]+|(?:[A-Z]+[a-z]+)+T?(?<!Type))(?:_co(?:ntra)?)?$"
),
- "typealias": re.compile(r"^_{0,2}(?!T[A-Z]|Type)[A-Z]+[a-z]+(?:[A-Z][a-z]+)*$"),
+ "typealias": re.compile(
+ r"^_{0,2}(?!T[A-Z]|Type)[A-Z]+[a-z0-9]+(?:[A-Z][a-z0-9]+)*$"
+ ),
}
BUILTIN_PROPERTY = "builtins.property"
diff --git a/tests/functional/t/typealias_naming_style_default.py b/tests/functional/t/typealias_naming_style_default.py
index a2d02c0c6..6b27c14a0 100644
--- a/tests/functional/t/typealias_naming_style_default.py
+++ b/tests/functional/t/typealias_naming_style_default.py
@@ -9,6 +9,8 @@ AnotherGoodName = Union[int, str]
GOODName: TypeAlias = int
GOODNAMEType: TypeAlias = int
TodoType: TypeAlias = int
+Good2Name: TypeAlias = int
+GoodName2: TypeAlias = int
# Non-PascalCase names
BadNAME: TypeAlias = int # [invalid-name]
@@ -20,6 +22,7 @@ BadNameT: TypeAlias = int # [invalid-name]
BAD_NAME = Union[int, str] # [invalid-name]
_BAD_NAME = Union[int, str] # [invalid-name]
__BAD_NAME = Union[int, str] # [invalid-name]
+_1BadName = Union[int, str] # [invalid-name]
ANOTHERBADNAME = Union[int, str] # [invalid-name]
# Regression tests
diff --git a/tests/functional/t/typealias_naming_style_default.txt b/tests/functional/t/typealias_naming_style_default.txt
index 237dac076..455cbc213 100644
--- a/tests/functional/t/typealias_naming_style_default.txt
+++ b/tests/functional/t/typealias_naming_style_default.txt
@@ -1,10 +1,11 @@
-invalid-name:14:0:14:7::"Type alias name ""BadNAME"" doesn't conform to predefined naming style":HIGH
-invalid-name:15:0:15:7::"Type alias name ""badName"" doesn't conform to predefined naming style":HIGH
-invalid-name:16:0:16:11::"Type alias name ""AlsoBADName"" doesn't conform to predefined naming style":HIGH
-invalid-name:17:0:17:8::"Type alias name ""TBadName"" doesn't conform to predefined naming style":HIGH
-invalid-name:18:0:18:8::"Type alias name ""TypeTodo"" doesn't conform to predefined naming style":HIGH
-invalid-name:19:0:19:8::"Type alias name ""BadNameT"" doesn't conform to predefined naming style":HIGH
-invalid-name:20:0:20:8::"Type alias name ""BAD_NAME"" doesn't conform to predefined naming style":HIGH
-invalid-name:21:0:21:9::"Type alias name ""_BAD_NAME"" doesn't conform to predefined naming style":HIGH
-invalid-name:22:0:22:10::"Type alias name ""__BAD_NAME"" doesn't conform to predefined naming style":HIGH
-invalid-name:23:0:23:14::"Type alias name ""ANOTHERBADNAME"" doesn't conform to predefined naming style":HIGH
+invalid-name:16:0:16:7::"Type alias name ""BadNAME"" doesn't conform to predefined naming style":HIGH
+invalid-name:17:0:17:7::"Type alias name ""badName"" doesn't conform to predefined naming style":HIGH
+invalid-name:18:0:18:11::"Type alias name ""AlsoBADName"" doesn't conform to predefined naming style":HIGH
+invalid-name:19:0:19:8::"Type alias name ""TBadName"" doesn't conform to predefined naming style":HIGH
+invalid-name:20:0:20:8::"Type alias name ""TypeTodo"" doesn't conform to predefined naming style":HIGH
+invalid-name:21:0:21:8::"Type alias name ""BadNameT"" doesn't conform to predefined naming style":HIGH
+invalid-name:22:0:22:8::"Type alias name ""BAD_NAME"" doesn't conform to predefined naming style":HIGH
+invalid-name:23:0:23:9::"Type alias name ""_BAD_NAME"" doesn't conform to predefined naming style":HIGH
+invalid-name:24:0:24:10::"Type alias name ""__BAD_NAME"" doesn't conform to predefined naming style":HIGH
+invalid-name:25:0:25:9::"Type alias name ""_1BadName"" doesn't conform to predefined naming style":HIGH
+invalid-name:26:0:26:14::"Type alias name ""ANOTHERBADNAME"" doesn't conform to predefined naming style":HIGH