Skip to content

Commit

Permalink
Merge branch 'unicode_checks' of https://github.com/CarliJoy/pylint i…
Browse files Browse the repository at this point in the history
…nto unicode_checks
  • Loading branch information
CarliJoy committed Jan 6, 2022
2 parents 9b59efe + e9e17c2 commit 01326cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Closes #5281
as non ASCII characters could be homoglyphs (look alike characters) and hard to
enter on a non specialized keyboard.


* ``unnecessary-ellipsis``: Emitted when the ellipsis constant is used unnecessarily.

Closes #5460
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
is_property_deleter,
is_property_setter,
)
from pylint.constants import HUMAN_READABLE_TYPES
from pylint.reporters.ureports import nodes as reporter_nodes
from pylint.utils import LinterStats
from pylint.utils.utils import get_global_option
Expand Down
18 changes: 10 additions & 8 deletions pylint/checkers/non_ascii_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
"""All alphanumeric unicode character are allowed in Python but could do
to similarities in their look, they can be confused.
"""All alphanumeric unicode character are allowed in Python but due
to similarities in how they look they can be confused.
See: https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers
Expand Down Expand Up @@ -59,7 +59,7 @@ class NonAsciiNamesChecker(pylint.checkers.BaseChecker):

msgs = {
"C0144": (
'%s name "%s" contains a non-ASCII character',
'%s name "%s" contains a non-ASCII character, rename it or use an alias for import',
"non-ascii-name",
(
"Used when the name contains at least one non-ASCII unicode character. "
Expand All @@ -71,7 +71,7 @@ class NonAsciiNamesChecker(pylint.checkers.BaseChecker):

name = "NonASCII-Checker"

def __init__(self, linter):
def __init__(self, linter: PyLinter) -> None:
super().__init__(linter)
self._non_ascii_rgx_compiled = re.compile("[^A-Za-z0-9_]")

Expand All @@ -95,7 +95,7 @@ def _check_name(
names: Union[str, List[str]],
node: Union[nodes.NodeNG, _AsciiOnlyCheckedNode],
) -> None:
"""check for a name if it's using non ASCII and set message if it does
"""Check whether a name is using non-ASCII characters.
Also set the dynamic attribute ``_is_ascii_only`` that is used to
determine if a node has been already checked, so we don't have to handle
Expand All @@ -109,16 +109,18 @@ def _check_name(
if name is None:
# For some nodes i.e. *kwargs from a dict, the name will be empty
continue
non_ascii_match = self._non_ascii_rgx_compiled.match(name)
if not (Py37Str(name).isascii() and non_ascii_match is None):
if not (
Py37Str(name).isascii()
and self._non_ascii_rgx_compiled.match(name) is None
):
# Note that we require the `.isascii` method as it is fast and
# handles the complexities of unicode, so we can use simple regex.
self._raise_name_warning(node, node_type, name)
current_state = False

node._is_ascii_only = current_state # pylint: disable=protected-access

def _recursive_check_names(self, args: Iterable[nodes.AssignName]):
def _recursive_check_names(self, args: Iterable[nodes.AssignName]) -> None:
"""check names in a possibly recursive list <arg>"""
for arg in args:
if isinstance(arg, nodes.AssignName):
Expand Down

0 comments on commit 01326cd

Please sign in to comment.