Skip to content

Commit 54709b8

Browse files
CarliJoyDanielNoord
andcommitted
Apply suggestions from code review
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent 7c0411a commit 54709b8

32 files changed

+61
-49
lines changed

ChangeLog

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ Release date: TBA
1414

1515
Closes #5588
1616

17-
* Add ``non-ascii-identifier`` as replacement ``non-ascii-name``
18-
to ensure really __all__ Python names are ASCII.
19-
Checker now checks properly the names of imports (``non-ascii-module-import``) as
20-
well for as of file names (``non-ascii-file-name``).
17+
* Renamed ``non-ascii-name`` to ``non-ascii-identifier`` and rewrote the checker.
18+
It now ensures __all__ Python names are ASCII and also properly
19+
checks the names of imports (``non-ascii-module-import``) as
20+
well as file names (``non-ascii-file-name``) and emits their respective new warnings.
21+
2122
Non ASCII characters could be homoglyphs (look alike characters) and hard to
2223
enter on a non specialized keyboard.
2324
See `Confusable Characters in PEP 672 <https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers>`_

doc/whatsnew/2.13.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ New checkers
1414

1515
Closes #5460
1616

17-
* Add ``non-ascii-identifier`` as replacement ``non-ascii-name``
18-
to ensure really __all__ Python names are ASCII.
19-
Checker now checks properly the names of imports (``non-ascii-module-import``) as
20-
well for as of file names (``non-ascii-file-name``).
17+
* Renamed ``non-ascii-name`` to ``non-ascii-identifier`` and rewrote the checker.
18+
It now ensures __all__ Python names are ASCII and also properly
19+
checks the names of imports (``non-ascii-module-import``) as
20+
well as file names (``non-ascii-file-name``) and emits their respective new warnings.
21+
2122
Non ASCII characters could be homoglyphs (look alike characters) and hard to
2223
enter on a non specialized keyboard.
2324
See `Confusable Characters in PEP 672 <https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers>`_
2425

2526
Removed checkers
2627
================
27-
* ``non-ascii-name`` has replaced by ``non-ascii-identifier``
28+
* ``non-ascii-name`` has been renamed to ``non-ascii-identifier``
2829

2930
Extensions
3031
==========

pylint/checkers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ def _check_name(
17321732
raise NotImplementedError
17331733

17341734
def _recursive_check_names(self, args: Iterable[nodes.AssignName]):
1735-
"""check names in a possibly recursive list <arg>"""
1735+
"""Check names in a possibly recursive list <arg>"""
17361736
for arg in args:
17371737
if isinstance(arg, nodes.AssignName):
17381738
self._check_name("argument", arg.name, arg)

pylint/checkers/non_ascii_names.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@ class NonAsciiNamesChecker(
6262

6363
msgs = {
6464
"C2401": (
65-
'%s name "%s" contains a non-ASCII character, rename it.',
65+
'%s name "%s" contains a non-ASCII character, consider renaming it.',
6666
"non-ascii-identifier",
6767
(
68-
"Used when the name contains at least one non-ASCII unicode character."
68+
"Used when the name contains at least one non-ASCII unicode character. "
6969
"See https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers"
7070
" for a background why this could be bad."
7171
),
7272
{"old_names": [("C0144", "non-ascii-name")]},
7373
),
7474
# First %s will always be "file"
7575
"W2402": (
76-
'%s name "%s" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers!',
76+
'%s name "%s" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers.',
7777
"non-ascii-file-name",
7878
(
7979
# Some = PyCharm at the time of writing didn't display the non_ascii_name_loł
8080
# files. Probably only a bug shows the problem quite good.
8181
# That's also why this is a warning and not only a convention!
8282
"Some editors don't support non-ASCII file names properly. "
83-
"Even so Python supports UTF-8 files since Python 3.5 this isn't recommended for"
84-
"interoperability. Further reading: \n"
85-
"- https://www.python.org/dev/peps/pep-0489/#export-hook-name \n"
83+
"Even so Python supports UTF-8 files since Python 3.5 this isn't recommended for "
84+
"interoperability. Further reading:\n"
85+
"- https://www.python.org/dev/peps/pep-0489/#export-hook-name\n"
8686
"- https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers\n"
8787
"- https://bugs.python.org/issue20485\n"
8888
),
@@ -173,17 +173,17 @@ def visit_functiondef(
173173
arguments = node.args
174174

175175
# Check position only arguments
176-
if arguments.posonlyargs is not None:
176+
if arguments.posonlyargs:
177177
for pos_only_arg in arguments.posonlyargs:
178178
self._check_name("argument", pos_only_arg.name, pos_only_arg)
179179

180180
# Check "normal" arguments
181181
args = arguments.args
182-
if args is not None:
182+
if args:
183183
self._recursive_check_names(args)
184184

185185
# Check key word only arguments
186-
if arguments.kwonlyargs is not None:
186+
if arguments.kwonlyargs:
187187
for kwarg in arguments.kwonlyargs:
188188
self._check_name("argument", kwarg.name, kwarg)
189189

tests/checkers/unittest_non_ascii_name.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def name(
3636
"""
3737
)
3838
assert isinstance(node, nodes.FunctionDef)
39-
arguments: nodes.Arguments = node.args
39+
arguments = node.args
4040

4141
posargs = list(arguments.posonlyargs)
4242
args = list(arguments.args)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
invalid-name:1:0:None:None::"Module name ""#emacs_file_lock_redefined_conf"" doesn't conform to snake_case naming style":HIGH
2-
non-ascii-file-name:1:0:None:None::"File name ""#emacs_file_lock_redefined_conf"" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers!":HIGH
2+
non-ascii-file-name:1:0:None:None::"File name ""#emacs_file_lock_redefined_conf"" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers.":HIGH
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
non-ascii-identifier:3:0:3:10::"Variable name ""áéíóú"" contains a non-ASCII character, rename it.":HIGH
2-
non-ascii-identifier:5:0:6:12:úóíéá:"Function name ""úóíéá"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:3:0:3:10::"Variable name ""áéíóú"" contains a non-ASCII character, consider renaming it.":HIGH
2+
non-ascii-identifier:5:0:6:12:úóíéá:"Function name ""úóíéá"" contains a non-ASCII character, consider renaming it.":HIGH

tests/functional/n/non/non_ascii_name_backward_test_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tests for non-ascii-name checker working as expected """
1+
""" Tests for non-ascii-name checker working as expected after a major refactor """
22
# pylint: disable=C0144, use-symbolic-message-instead
33

44
áéíóú = 4444

tests/functional/n/non/non_ascii_name_backward_test_msg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tests for non-ascii-name checker working as expected """
1+
""" Tests for non-ascii-name checker working as expected after a major refactor """
22
# pylint: disable=non-ascii-name
33

44
áéíóú = 4444

tests/functional/n/non_ascii_import/foobar.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-file-name:1:0:None:None::"File name ""non_ascii_name_loł"" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers!":HIGH
1+
non-ascii-file-name:1:0:None:None::"File name ""non_ascii_name_loł"" contains a non-ASCII character. PEP 3131 only allows non-ascii identifiers.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:3:4:3:8::"Variable name ""loł"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:3:4:3:8::"Variable name ""loł"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:10:8:10:12:main:"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:10:8:10:12:main:"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:13:0:15:28:sayНello:"Function name ""sayНello"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:13:0:15:28:sayНello:"Function name ""sayНello"" contains a non-ASCII character, consider renaming it.":HIGH

tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py38.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
22
non ascii variable defined in a function
3+
4+
This test is only for 3.8 as the starting column is incorrect
35
"""
46

57

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
non-ascii-identifier:9:4:9:13:okay:"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
2-
non-ascii-identifier:21:0:None:None::"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:11:4:11:13:okay:"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
2+
non-ascii-identifier:23:0:None:None::"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH

tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
non ascii variable defined in a function
3+
4+
This test is 3.9+ and not using 'min_pyver_end_position'
5+
as the starting column is also incorrect on < 3.9
36
"""
47

58

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
non-ascii-identifier:9:4:9:13:okay:"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
2-
non-ascii-identifier:21:4:21:12::"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:12:4:12:13:okay:"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
2+
non-ascii-identifier:24:4:24:12::"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:7:8:7:12::"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:7:8:7:12::"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH

tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py38.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
22
Defining non ASCII variables in a function call
3+
4+
This test is only for 3.8 as the starting column is incorrect
35
"""
46

57

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:14:0:None:None::"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:16:0:None:None::"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH

tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
Defining non ASCII variables in a function call
3+
4+
This test is 3.9+ and not using 'min_pyver_end_position'
5+
as the starting column is also incorrect on < 3.9
36
"""
47

58

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:14:4:14:10::"Argument name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:17:4:17:10::"Argument name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:6:4:6:8:okay:"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:6:4:6:8:okay:"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
non-ascii-identifier:9:4:9:17:name:"Argument name ""not_okay_łol"" contains a non-ASCII character, rename it.":HIGH
2-
non-ascii-identifier:10:4:10:21:name:"Argument name ""not_okay_defaułt"" contains a non-ASCII character, rename it.":HIGH
3-
non-ascii-identifier:13:4:13:21:name:"Argument name ""p_or_kw_not_økay"" contains a non-ASCII character, rename it.":HIGH
4-
non-ascii-identifier:16:4:16:20:name:"Argument name ""kw_arg_not_økay"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:9:4:9:17:name:"Argument name ""not_okay_łol"" contains a non-ASCII character, consider renaming it.":HIGH
2+
non-ascii-identifier:10:4:10:21:name:"Argument name ""not_okay_defaułt"" contains a non-ASCII character, consider renaming it.":HIGH
3+
non-ascii-identifier:13:4:13:21:name:"Argument name ""p_or_kw_not_økay"" contains a non-ASCII character, consider renaming it.":HIGH
4+
non-ascii-identifier:16:4:16:20:name:"Argument name ""kw_arg_not_økay"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:11:4:13:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:11:4:13:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:9:0:11:14::"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:9:0:11:14::"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
non-ascii-identifier:7:0:7:4::"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
2-
non-ascii-identifier:9:0:9:4::"Variable name ""łol"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:7:0:7:4::"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
2+
non-ascii-identifier:9:0:9:4::"Variable name ""łol"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:5:0:10:19:НoldIt:"Class name ""НoldIt"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:5:0:10:19:НoldIt:"Class name ""НoldIt"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:12:8:12:22:OkayIsh.__init__:"Attribute name ""łoopback"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:12:8:12:22:OkayIsh.__init__:"Attribute name ""łoopback"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:6:4:6:13:OkayIsh:"Attribute name ""ŁOOPBACK"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:6:4:6:13:OkayIsh:"Attribute name ""ŁOOPBACK"" contains a non-ASCII character, consider renaming it.":HIGH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
non-ascii-identifier:12:4:14:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character, rename it.":HIGH
1+
non-ascii-identifier:12:4:14:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character, consider renaming it.":HIGH

0 commit comments

Comments
 (0)