From dcf244ae12b6e698e2ca2fedcdbe29812c19cad0 Mon Sep 17 00:00:00 2001 From: Carli* Freudenberg Date: Thu, 6 Jan 2022 19:28:18 +0100 Subject: [PATCH] remove non-ascii-checker --- ChangeLog | 4 - base_checker.py | 203 +++++++++++++++ doc/whatsnew/2.13.rst | 5 - pylint/checkers/base.py | 33 ++- pylint/checkers/non_ascii_names.py | 239 ------------------ pylint/testutils/checker_test_case.py | 15 +- tests/checkers/unittest_non_ascii_name.py | 204 --------------- tests/functional/n/non/non_ascii_name.txt | 4 +- tests/functional/n/non_ascii_name/__init__.py | 0 .../non_ascii_name_assignment_expressions.py | 4 - .../non_ascii_name_assignment_expressions.rc | 2 - .../non_ascii_name_assignment_expressions.txt | 1 - .../n/non_ascii_name/non_ascii_name_class.py | 17 -- .../n/non_ascii_name/non_ascii_name_class.txt | 1 - .../non_ascii_name_class_attribute.py | 25 -- .../non_ascii_name_class_attribute.txt | 1 - .../non_ascii_name_class_constant.py | 23 -- .../non_ascii_name_class_constant.txt | 1 - .../non_ascii_name_class_method.py | 18 -- .../non_ascii_name_class_method.txt | 1 - .../non_ascii_name_dict_kwargs.py | 13 - .../non_ascii_name/non_ascii_name_for_loop.py | 14 - .../non_ascii_name_for_loop.txt | 1 - .../non_ascii_name/non_ascii_name_function.py | 19 -- .../non_ascii_name_function.txt | 1 - ..._ascii_name_function_argument_py37minus.py | 22 -- ..._ascii_name_function_argument_py37minus.rc | 2 - ...ascii_name_function_argument_py37minus.txt | 2 - ...n_ascii_name_function_argument_py39plus.py | 22 -- ...n_ascii_name_function_argument_py39plus.rc | 2 - ..._ascii_name_function_argument_py39plus.txt | 2 - .../non_ascii_name_import_as.py | 6 - .../non_ascii_name_import_as.txt | 1 - .../non_ascii_name_import_from_as.py | 6 - .../non_ascii_name_import_from_as.txt | 1 - .../non_ascii_name_inline_var.py | 8 - .../non_ascii_name_inline_var.txt | 1 - .../non_ascii_name_kwargs_py37minus.py | 15 -- .../non_ascii_name_kwargs_py37minus.rc | 2 - .../non_ascii_name_kwargs_py37minus.txt | 1 - .../non_ascii_name_kwargs_py39plus.py | 15 -- .../non_ascii_name_kwargs_py39plus.rc | 2 - .../non_ascii_name_kwargs_py39plus.txt | 1 - .../n/non_ascii_name/non_ascii_name_local.py | 9 - .../n/non_ascii_name/non_ascii_name_local.txt | 1 - .../non_ascii_name_pos_and_kwonly_function.py | 21 -- .../non_ascii_name_pos_and_kwonly_function.rc | 2 - ...non_ascii_name_pos_and_kwonly_function.txt | 4 - .../non_ascii_name_staticmethod.py | 17 -- .../non_ascii_name_staticmethod.txt | 1 - .../non_ascii_name_try_except.py | 11 - .../non_ascii_name_try_except.txt | 1 - .../non_ascii_name/non_ascii_name_variable.py | 9 - .../non_ascii_name_variable.txt | 2 - 54 files changed, 232 insertions(+), 806 deletions(-) create mode 100644 base_checker.py delete mode 100644 pylint/checkers/non_ascii_names.py delete mode 100644 tests/checkers/unittest_non_ascii_name.py delete mode 100644 tests/functional/n/non_ascii_name/__init__.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_constant.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_constant.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_method.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_class_method.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_dict_kwargs.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_for_loop.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_for_loop.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_import_as.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_import_as.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_inline_var.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_inline_var.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_local.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_local.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.rc delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_try_except.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_try_except.txt delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_variable.py delete mode 100644 tests/functional/n/non_ascii_name/non_ascii_name_variable.txt diff --git a/ChangeLog b/ChangeLog index f7e5678a34a..0d9c42f85ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,10 +31,6 @@ Release date: TBA Closes #5281 -* ``non-ascii-name`` check was rewritten to ensure really __all__ Python names are ASCII - as non ASCII characters could be homoglyphs (look alike characters) and hard to - enter on a non specialized keyboard. - * Fixed false positive ``consider-using-dict-comprehension`` when creating a dict using a list of tuples where key AND value vary depending on the same condition. diff --git a/base_checker.py b/base_checker.py new file mode 100644 index 00000000000..5a6efd20c2f --- /dev/null +++ b/base_checker.py @@ -0,0 +1,203 @@ +# Copyright (c) 2006-2014 LOGILAB S.A. (Paris, FRANCE) +# Copyright (c) 2013-2014 Google, Inc. +# Copyright (c) 2013 buck@yelp.com +# Copyright (c) 2014-2020 Claudiu Popa +# Copyright (c) 2014 Brett Cannon +# Copyright (c) 2014 Arun Persaud +# Copyright (c) 2015 Ionel Cristian Maries +# Copyright (c) 2016 Moises Lopez +# Copyright (c) 2017-2018 Bryce Guinta +# Copyright (c) 2018-2021 Pierre Sassoulas +# Copyright (c) 2018 ssolanki +# Copyright (c) 2019 Bruno P. Kinoshita +# Copyright (c) 2020 hippo91 +# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> +# Copyright (c) 2021 bot +# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> + +# 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 +import functools +from inspect import cleandoc +from typing import Any, Optional + +from astroid import nodes + +from pylint.config import OptionsProviderMixIn +from pylint.constants import _MSG_ORDER, WarningScope +from pylint.exceptions import InvalidMessageError +from pylint.interfaces import Confidence, IRawChecker, ITokenChecker, implements +from pylint.message.message_definition import MessageDefinition +from pylint.utils import get_rst_section, get_rst_title + + +@functools.total_ordering +class BaseChecker(OptionsProviderMixIn): + + # checker name (you may reuse an existing one) + name: str = "" + # options level (0 will be displaying in --help, 1 in --long-help) + level = 1 + # ordered list of options to control the checker behaviour + options: Any = () + # messages issued by this checker + msgs: Any = {} + # reports issued by this checker + reports: Any = () + # mark this checker as enabled or not. + enabled: bool = True + + def __init__(self, linter=None): + """checker instances should have the linter as argument + + :param ILinter linter: is an object implementing ILinter. + """ + if self.name is not None: + self.name = self.name.lower() + super().__init__() + self.linter = linter + + def __gt__(self, other): + """Permit to sort a list of Checker by name.""" + return f"{self.name}{self.msgs}".__gt__(f"{other.name}{other.msgs}") + + def __repr__(self): + status = "Checker" if self.enabled else "Disabled checker" + msgs = "', '".join(self.msgs.keys()) + return f"{status} '{self.name}' (responsible for '{msgs}')" + + def __str__(self): + """This might be incomplete because multiple class inheriting BaseChecker + can have the same name. Cf MessageHandlerMixIn.get_full_documentation() + """ + return self.get_full_documentation( + msgs=self.msgs, options=self.options_and_values(), reports=self.reports + ) + + def get_full_documentation(self, msgs, options, reports, doc=None, module=None): + result = "" + checker_title = f"{self.name.replace('_', ' ').title()} checker" + if module: + # Provide anchor to link against + result += f".. _{module}:\n\n" + result += f"{get_rst_title(checker_title, '~')}\n" + if module: + result += f"This checker is provided by ``{module}``.\n" + result += f"Verbatim name of the checker is ``{self.name}``.\n\n" + if doc: + # Provide anchor to link against + result += get_rst_title(f"{checker_title} Documentation", "^") + result += f"{cleandoc(doc)}\n\n" + # options might be an empty generator and not be False when cast to boolean + options = list(options) + if options: + result += get_rst_title(f"{checker_title} Options", "^") + result += f"{get_rst_section(None, options)}\n" + if msgs: + result += get_rst_title(f"{checker_title} Messages", "^") + for msgid, msg in sorted( + msgs.items(), key=lambda kv: (_MSG_ORDER.index(kv[0][0]), kv[1]) + ): + msg = self.create_message_definition_from_tuple(msgid, msg) + result += f"{msg.format_help(checkerref=False)}\n" + result += "\n" + if reports: + result += get_rst_title(f"{checker_title} Reports", "^") + for report in reports: + result += ( + ":%s: %s\n" % report[:2] # pylint: disable=consider-using-f-string + ) + result += "\n" + result += "\n" + return result + + def add_message( + self, + msgid: str, + line: Optional[int] = None, + node: Optional[nodes.NodeNG] = None, + args: Any = None, + confidence: Optional[Confidence] = None, + col_offset: Optional[int] = None, + end_lineno: Optional[int] = None, + end_col_offset: Optional[int] = None, + ) -> None: + self.linter.add_message( + msgid, line, node, args, confidence, col_offset, end_lineno, end_col_offset + ) + + def check_consistency(self): + """Check the consistency of msgid. + + msg ids for a checker should be a string of len 4, where the two first + characters are the checker id and the two last the msg id in this + checker. + + :raises InvalidMessageError: If the checker id in the messages are not + always the same. + """ + checker_id = None + existing_ids = [] + for message in self.messages: + if checker_id is not None and checker_id != message.msgid[1:3]: + error_msg = "Inconsistent checker part in message id " + error_msg += f"'{message.msgid}' (expected 'x{checker_id}xx' " + error_msg += f"because we already had {existing_ids})." + raise InvalidMessageError(error_msg) + checker_id = message.msgid[1:3] + existing_ids.append(message.msgid) + + def create_message_definition_from_tuple(self, msgid, msg_tuple): + if implements(self, (IRawChecker, ITokenChecker)): + default_scope = WarningScope.LINE + else: + default_scope = WarningScope.NODE + options = {} + if len(msg_tuple) > 3: + (msg, symbol, descr, options) = msg_tuple + elif len(msg_tuple) > 2: + (msg, symbol, descr) = msg_tuple + else: + error_msg = """Messages should have a msgid and a symbol. Something like this : + +"W1234": ( + "message", + "message-symbol", + "Message description with detail.", + ... +), +""" + raise InvalidMessageError(error_msg) + options.setdefault("scope", default_scope) + return MessageDefinition(self, msgid, msg, descr, symbol, **options) + + @property + def messages(self) -> list: + return [ + self.create_message_definition_from_tuple(msgid, msg_tuple) + for msgid, msg_tuple in sorted(self.msgs.items()) + ] + + # dummy methods implementing the IChecker interface + + def get_message_definition(self, msgid): + for message_definition in self.messages: + if message_definition.msgid == msgid: + return message_definition + error_msg = f"MessageDefinition for '{msgid}' does not exists. " + error_msg += f"Choose from {[m.msgid for m in self.messages]}." + raise InvalidMessageError(error_msg) + + def open(self): + """called before visiting project (i.e. set of modules)""" + + def close(self): + """called after visiting project (i.e set of modules)""" + + +class BaseTokenChecker(BaseChecker): + """Base class for checkers that want to have access to the token stream.""" + + def process_tokens(self, tokens): + """Should be overridden by subclasses.""" + raise NotImplementedError() diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 1abb2cce340..3e60b4c4235 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -33,11 +33,6 @@ New checkers Closes #5281 - -* ``non-ascii-name`` check was rewritten to ensure really __all__ Python names are ASCII as - 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 diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 8ce7719c94c..2fe6123f1d3 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -78,7 +78,7 @@ import astroid from astroid import nodes -from pylint import checkers, interfaces +from pylint import checkers, constants, interfaces from pylint import utils as lint_utils from pylint.checkers import utils from pylint.checkers.utils import ( @@ -1690,7 +1690,7 @@ def visit_for(self, node: nodes.For) -> None: def _create_naming_options(): name_options = [] for name_type in sorted(KNOWN_NAME_TYPES): - human_readable_name = HUMAN_READABLE_TYPES[name_type] + human_readable_name = constants.HUMAN_READABLE_TYPES[name_type] default_style = DEFAULT_NAMING_STYLES[name_type] name_type = name_type.replace("_", "-") name_options.append( @@ -1737,6 +1737,11 @@ class NameChecker(_BasicChecker): ] }, ), + "C0144": ( + '%s name "%s" contains a non-ASCII unicode character', + "non-ascii-name", + "Used when the name contains at least one non-ASCII unicode character.", + ), "W0111": ( "Name %s will become a keyword in Python %s", "assign-to-new-keyword", @@ -1833,6 +1838,7 @@ def __init__(self, linter): self._name_hints = {} self._good_names_rgxs_compiled = [] self._bad_names_rgxs_compiled = [] + self._non_ascii_rgx_compiled = re.compile("[^\u0000-\u007F]") def open(self): self.linter.stats.reset_bad_names() @@ -1872,7 +1878,7 @@ def _create_naming_rules(self): return regexps, hints - @utils.check_messages("disallowed-name", "invalid-name") + @utils.check_messages("disallowed-name", "invalid-name", "non-ascii-name") def visit_module(self, node: nodes.Module) -> None: self._check_name("module", node.name.split(".")[-1], node) self._bad_names = {} @@ -1898,7 +1904,9 @@ def leave_module(self, _: nodes.Module) -> None: for args in warnings: self._raise_name_warning(prevalent_group, *args) - @utils.check_messages("disallowed-name", "invalid-name", "assign-to-new-keyword") + @utils.check_messages( + "disallowed-name", "invalid-name", "assign-to-new-keyword", "non-ascii-name" + ) def visit_classdef(self, node: nodes.ClassDef) -> None: self._check_assign_to_new_keyword_violation(node.name, node) self._check_name("class", node.name, node) @@ -1906,7 +1914,9 @@ def visit_classdef(self, node: nodes.ClassDef) -> None: if not any(node.instance_attr_ancestors(attr)): self._check_name("attr", attr, anodes[0]) - @utils.check_messages("disallowed-name", "invalid-name", "assign-to-new-keyword") + @utils.check_messages( + "disallowed-name", "invalid-name", "assign-to-new-keyword", "non-ascii-name" + ) def visit_functiondef(self, node: nodes.FunctionDef) -> None: # Do not emit any warnings if the method is just an implementation # of a base class method. @@ -1934,12 +1944,14 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None: visit_asyncfunctiondef = visit_functiondef - @utils.check_messages("disallowed-name", "invalid-name") + @utils.check_messages("disallowed-name", "invalid-name", "non-ascii-name") def visit_global(self, node: nodes.Global) -> None: for name in node.names: self._check_name("const", name, node) - @utils.check_messages("disallowed-name", "invalid-name", "assign-to-new-keyword") + @utils.check_messages( + "disallowed-name", "invalid-name", "assign-to-new-keyword", "non-ascii-name" + ) def visit_assignname(self, node: nodes.AssignName) -> None: """check module level assigned names""" self._check_assign_to_new_keyword_violation(node.name, node) @@ -1999,7 +2011,7 @@ def _raise_name_warning( confidence, warning: str = "invalid-name", ) -> None: - type_label = HUMAN_READABLE_TYPES[node_type] + type_label = constants.HUMAN_READABLE_TYPES[node_type] hint = self._name_hints[node_type] if prevalent_group: # This happens in the multi naming match case. The expected @@ -2029,6 +2041,11 @@ def _name_disallowed_by_regex(self, name: str) -> bool: def _check_name(self, node_type, name, node, confidence=interfaces.HIGH): """check for a name using the type's regexp""" + non_ascii_match = self._non_ascii_rgx_compiled.match(name) + if non_ascii_match is not None: + self._raise_name_warning( + None, node, node_type, name, confidence, warning="non-ascii-name" + ) def _should_exempt_from_invalid_name(node): if node_type == "variable": diff --git a/pylint/checkers/non_ascii_names.py b/pylint/checkers/non_ascii_names.py deleted file mode 100644 index 40c161d8bc8..00000000000 --- a/pylint/checkers/non_ascii_names.py +++ /dev/null @@ -1,239 +0,0 @@ -# Copyright (c) 2021-2022 Carli Freudenberg - -# 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 due -to similarities in how they look they can be confused. - -See: https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers - -The following checkers are intended to make users are aware of these issues. -""" - -import re -import sys -from typing import Iterable, List, Optional, Union - -from astroid import nodes - -import pylint.checkers.utils -from pylint import interfaces -from pylint.constants import HUMAN_READABLE_TYPES -from pylint.lint import PyLinter - -if sys.version_info >= (3, 8): - from typing import Protocol -else: - from typing_extensions import Protocol - - -if sys.version_info[:2] >= (3, 7): - # pylint: disable-next=fixme - # TODO: Remove after 3.6 has been deprecated - Py37Str = str -else: - - class Py37Str(str): - # Allow Python 3.6 compatibility - def isascii(self: str) -> bool: - return all("\u0000" <= x <= "\u007F" for x in self) - - -class _AsciiOnlyCheckedNode(Protocol): - _is_ascii_only: bool - - -class NonAsciiNamesChecker(pylint.checkers.BaseChecker): - """A strict name checker only allowing ASCII - - If your programming guideline defines that you are programming in English, - then there should be no need for non ASCII characters in Python Names. - Everybody else can simply not use this check. - - Note: This check only checks Names, so it ignores the content of - docstrings and comments! - """ - - __implements__ = interfaces.IAstroidChecker - priority = -1 - - msgs = { - "C0144": ( - '%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. " - "See https://www.python.org/dev/peps/pep-0672/#confusable-characters-in-identifiers" - " for a background why this could be bad." - ), - ), - } - - name = "NonASCII-Checker" - - def __init__(self, linter: PyLinter) -> None: - super().__init__(linter) - self._non_ascii_rgx_compiled = re.compile("[^A-Za-z0-9_]") - - def _raise_name_warning( - self, - node: nodes.NodeNG, - node_type: str, - name: str, - ) -> None: - type_label = HUMAN_READABLE_TYPES[node_type] - args = (type_label.capitalize(), name) - - self.add_message( - "non-ascii-name", node=node, args=args, confidence=interfaces.HIGH - ) - self.linter.stats.increase_bad_name(node_type, 1) - - def _check_name( - self, - node_type: str, - names: Union[str, List[str]], - node: Union[nodes.NodeNG, _AsciiOnlyCheckedNode], - ) -> None: - """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 - too many edge cases. - """ - if not isinstance(names, list): - names = [names] - - current_state = getattr(node, "_is_ascii_only", True) - for name in names: - if name is None: - # For some nodes i.e. *kwargs from a dict, the name will be empty - continue - 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]) -> None: - """check names in a possibly recursive list """ - for arg in args: - if isinstance(arg, nodes.AssignName): - self._check_name("argument", arg.name, arg) - else: - # pylint: disable-next=fixme - # TODO: Check if we can remove this branch because of - # the up to date astroid version used - self._recursive_check_names(arg.elts) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_module(self, node: nodes.Module) -> None: - # pylint: disable-next=fixme - # TODO check how the node name is defined when calling the real checker - # in the test using the astroid manager the node.name attribute corresponds - # to the filename -> so we always have ".py" as result of the following - # function. - # It would be nice if we could check for an ASCII filename, if not done - # already by other checkers... - self._check_name("module", node.name.split(".")[-1], node) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_functiondef( - self, node: Union[nodes.FunctionDef, nodes.AsyncFunctionDef] - ) -> None: - self._check_name("function", node.name, node) - - # Check argument names - arguments = node.args - - # Check position only arguments - if arguments.posonlyargs is not None: - for pos_only_arg in arguments.posonlyargs: - self._check_name("argument", pos_only_arg.name, pos_only_arg) - - # Check "normal" arguments - args = arguments.args - if args is not None: - self._recursive_check_names(args) - - # Check key word only arguments - if arguments.kwonlyargs is not None: - for kwarg in arguments.kwonlyargs: - self._check_name("argument", kwarg.name, kwarg) - - visit_asyncfunctiondef = visit_functiondef - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_global(self, node: nodes.Global) -> None: - for name in node.names: - self._check_name("const", name, node) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_assignname(self, node: nodes.AssignName) -> None: - """check module level assigned names""" - frame = node.frame() - assign_type = node.assign_type() - if isinstance(assign_type, nodes.Comprehension): - # original inlinevar - self._check_name("variable", node.name, node) - elif isinstance(frame, nodes.Module): - # Here a lot of checks were done in the original module, - # but we call it a day and say everything is variable - self._check_name("variable", node.name, node) - elif isinstance(frame, nodes.FunctionDef): - if not hasattr(node, "_is_ascii_only"): - # only check if not already done - self._check_name("variable", node.name, node) - elif isinstance(frame, nodes.ClassDef): - self._check_name("attr", node.name, node) - else: - # Just to make sure we check EVERYTHING (!) - self._check_name("variable", node.name, node) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_classdef(self, node: nodes.ClassDef) -> None: - self._check_name("class", node.name, node) - for attr, anodes in node.instance_attrs.items(): - if not any(node.instance_attr_ancestors(attr)): - self._check_name("attr", attr, anodes[0]) - - @staticmethod - def _get_module_names(module_name: str, alias: Optional[str] = None) -> List[str]: - result = module_name.split(".") - if alias is not None: - result.append(alias) - return result - - def _check_module_import( - self, node: Union[nodes.ImportFrom, nodes.Import], is_import_from: bool = False - ): - names = [] - for module_name, alias in node.names: - names += self._get_module_names(module_name, alias) - if not (is_import_from and names == ["*"]): - # Ignore ``from xyz import *`` - self._check_name("module", names, node) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_import(self, node: nodes.Import) -> None: - self._check_module_import(node) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_importfrom(self, node: nodes.ImportFrom) -> None: - self._check_name("module", self._get_module_names(node.modname), node) - self._check_module_import(node, is_import_from=True) - - @pylint.checkers.utils.check_messages("non-ascii-name") - def visit_call(self, node: nodes.Call) -> None: - # lets check if the used keyword args are correct - for keyword in node.keywords: - self._check_name("argument", keyword.arg, keyword) - - -def register(linter: PyLinter) -> None: - linter.register_checker(NonAsciiNamesChecker(linter)) diff --git a/pylint/testutils/checker_test_case.py b/pylint/testutils/checker_test_case.py index adbd1ae91f8..af72136a9d3 100644 --- a/pylint/testutils/checker_test_case.py +++ b/pylint/testutils/checker_test_case.py @@ -32,18 +32,12 @@ def assertNoMessages(self): yield @contextlib.contextmanager - def assertAddsMessages( - self, *messages: MessageTest, ignore_position: bool = False - ) -> Generator[None, None, None]: + def assertAddsMessages(self, *messages: MessageTest) -> Generator[None, None, None]: """Assert that exactly the given method adds the given messages. The list of messages must exactly match *all* the messages added by the method. Additionally, we check to see whether the args in each message can actually be substituted into the message string. - - Using the keyword argument `ignore_position`, all checks for position - arguments (line, col_offset, ...) will be skipped. This can be used to - just test for the node for instance. """ yield got = self.linter.release_messages() @@ -59,15 +53,10 @@ def assertAddsMessages( for expected_msg, gotten_msg in zip(messages, got): assert expected_msg.msg_id == gotten_msg.msg_id, msg + assert expected_msg.line == gotten_msg.line, msg assert expected_msg.node == gotten_msg.node, msg assert expected_msg.args == gotten_msg.args, msg assert expected_msg.confidence == gotten_msg.confidence, msg - - if ignore_position: - # Do not check for line, col_offset etc... - continue - - assert expected_msg.line == gotten_msg.line, msg assert expected_msg.col_offset == gotten_msg.col_offset, msg if PY38_PLUS: # pylint: disable=fixme diff --git a/tests/checkers/unittest_non_ascii_name.py b/tests/checkers/unittest_non_ascii_name.py deleted file mode 100644 index 499114a86e4..00000000000 --- a/tests/checkers/unittest_non_ascii_name.py +++ /dev/null @@ -1,204 +0,0 @@ -import sys - -import astroid -import pytest -from astroid import nodes - -import pylint.checkers.non_ascii_names -import pylint.interfaces -import pylint.testutils - - -class TestNonAsciiChecker(pylint.testutils.CheckerTestCase): - CHECKER_CLASS = pylint.checkers.non_ascii_names.NonAsciiNamesChecker - checker: pylint.checkers.non_ascii_names.NonAsciiNamesChecker - - EXPECTED_MSG = "non-ascii-name" - - def test_get_module_names(self): - """The static function _get_modules_names shall resolve module names correctly""" - assert self.CHECKER_CLASS._get_module_names("foo.bar.test") == [ - "foo", - "bar", - "test", - ] - assert self.CHECKER_CLASS._get_module_names("foo.bar", "test") == [ - "foo", - "bar", - "test", - ] - - @pytest.mark.skipif( - sys.version_info < (3, 8), reason="requires python3.8 or higher" - ) - def test_kwargs_and_position_only(self): - """Even the new position only and keyword only should be found""" - node = astroid.extract_node( - """ - def name( - ok, - not_økay, - not_okay_defaułt=None, - /, - p_or_kw_okay=None, - p_or_kw_not_økay=None, - *, - kw_arg_okay, - kw_arg_not_økay, - ): - ... - """ - ) - assert isinstance(node, nodes.FunctionDef) - arguments: nodes.Arguments = node.args - - posargs = list(arguments.posonlyargs) - args = list(arguments.args) - kwargs = list(arguments.kwonlyargs) - - with self.assertAddsMessages( - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=posargs[1], - args=("Argument", "not_økay"), - confidence=pylint.interfaces.HIGH, - ), - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=posargs[2], - args=("Argument", "not_okay_defaułt"), - confidence=pylint.interfaces.HIGH, - ), - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=args[1], - args=("Argument", "p_or_kw_not_økay"), - confidence=pylint.interfaces.HIGH, - ), - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=kwargs[1], - args=("Argument", "kw_arg_not_økay"), - confidence=pylint.interfaces.HIGH, - ), - ignore_position=True, - ): - self.checker.visit_functiondef(node) - - @pytest.mark.parametrize( - "code, assign_type", - [ - pytest.param( - """ - try: - ... - except ValueError as łol: #@ - ... - """, - "Variable", - id="try-except", - ), - pytest.param( - """ - class FooBar: - łol = "test" #@ - """, - "Attribute", - id="class_attribute", - ), - pytest.param( - """ - łol = "test" #@ - """, - "Variable", - id="global_assign", - ), - pytest.param( - """ - def foobar(): - łol="test" #@ - """, - "Variable", - id="function_variable", - ), - pytest.param( - """ - for łol in os.listdir("."): #@ - ... - """, - "Variable", - id="for_loop_variable", - ), - pytest.param( - """ - [łoł - for łol in os.listdir(".") #@ - ] - """, - "Variable", - id="inline_for_loop_variable", - ), - ], - ) - def test_assignname( - self, - code: str, - assign_type: str, - ): - """Variables defined no matter where, should be checked for non ascii""" - assign_node = astroid.extract_node(code) - - if not isinstance(assign_node, nodes.AssignName): - # For some elements we can't directly extract the assign - # node, so we have to manually look in the children for it - for child in assign_node.get_children(): - if isinstance(child, nodes.AssignName): - assign_node = child - break - - # Just to make sure we found the correct node - assert isinstance(assign_node, nodes.AssignName) - - with self.assertAddsMessages( - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=assign_node, - args=(assign_type, "łol"), - confidence=pylint.interfaces.HIGH, - ), - ignore_position=True, - ): - self.checker.visit_assignname(assign_node) - - def test_class_definition(self): - node = astroid.extract_node( - """ - class FooBär: #@ - ... - """ - ) - assert isinstance(node, nodes.ClassDef) - - with self.assertAddsMessages( - pylint.testutils.MessageTest( - msg_id=self.EXPECTED_MSG, - node=node, - args=("Class", "FooBär"), - confidence=pylint.interfaces.HIGH, - line=2, - col_offset=0, - # pylint: disable-next=fixme - # TODO: Maybe we have to select something different - # here, as line 3 is not that thing we expect - end_line=3, - end_col_offset=7, - ) - ): - self.checker.visit_classdef(node) - - def test_import_ignore_star(self): - """Special case from xyz import *, where '*' is not A-Za-z0-9 but still valid""" - node = astroid.parse("from urllib.parse import *") - - with self.assertAddsMessages(): - self.walk(node) diff --git a/tests/functional/n/non/non_ascii_name.txt b/tests/functional/n/non/non_ascii_name.txt index 03c81590251..ba5338bb96f 100644 --- a/tests/functional/n/non/non_ascii_name.txt +++ b/tests/functional/n/non/non_ascii_name.txt @@ -1,2 +1,2 @@ -non-ascii-name:3:0:3:10::"Variable name ""áéíóú"" contains a non-ASCII character":HIGH -non-ascii-name:5:0:6:12:úóíéá:"Function name ""úóíéá"" contains a non-ASCII character":HIGH +non-ascii-name:3:0:3:10::"Constant name ""áéíóú"" contains a non-ASCII unicode character":HIGH +non-ascii-name:5:0:6:12:úóíéá:"Function name ""úóíéá"" contains a non-ASCII unicode character":HIGH diff --git a/tests/functional/n/non_ascii_name/__init__.py b/tests/functional/n/non_ascii_name/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.py b/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.py deleted file mode 100644 index ac51b9c4dc3..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.py +++ /dev/null @@ -1,4 +0,0 @@ -"""Assigment Expression as defined in https://www.python.org/dev/peps/pep-0572/""" - -if (loł := __name__) == "__main__": # [non-ascii-name] - print(loł) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.rc b/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.rc deleted file mode 100644 index 85fc502b372..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.8 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.txt b/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.txt deleted file mode 100644 index 121321dbc1c..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_assignment_expressions.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:3:4:3:8::"Variable name ""loł"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class.py b/tests/functional/n/non_ascii_name/non_ascii_name_class.py deleted file mode 100644 index f2e68426a7d..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class.py +++ /dev/null @@ -1,17 +0,0 @@ -""" Non ASCII char in class name """ -# pylint: disable=too-few-public-methods - - -class НoldIt: # [non-ascii-name] - """nice classs""" - - def public(self): - """do something""" - print(self) - - -def main(): - """Main function""" - # Usage should not raise a second error - foobar = НoldIt() - print(foobar) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class.txt b/tests/functional/n/non_ascii_name/non_ascii_name_class.txt deleted file mode 100644 index 889d905c49b..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:5:0:10:19:НoldIt:"Class name ""НoldIt"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.py b/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.py deleted file mode 100644 index 07d95bba566..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Non ASCII name in class variable""" - - -class OkayIsh: - """Class docstring""" - - def public(self): - """Be public!""" - print(self) - - def __init__(self): - self.łoopback = "invalid" # [non-ascii-name] - - def foobar(self): - """do something""" - # Usage should not raise a second error - return self.łoopback - -def main(): - """main function""" - # Usage should not raise a second error - barrrr = OkayIsh() - barrrr.foobar() - test = barrrr.łoopback - print(test) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.txt b/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.txt deleted file mode 100644 index 8d27e71eeca..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_attribute.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:12:8:12:22:OkayIsh.__init__:"Attribute name ""łoopback"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.py b/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.py deleted file mode 100644 index c3f96cadd90..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.py +++ /dev/null @@ -1,23 +0,0 @@ -"""non ASCII name in global class variable/class constant""" - - -class OkayIsh: - """Class docstring""" - ŁOOPBACK = "invalid" # [non-ascii-name] - - - def more_public(self): - """yet another public method""" - print(self) - - def public(self): - """something public""" - print(self) - - - -def main(): - """Main func""" - # Usage should not raise a second error - foobar = OkayIsh.ŁOOPBACK - print(foobar) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.txt b/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.txt deleted file mode 100644 index 0001318a89e..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_constant.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:6:4:6:13:OkayIsh:"Attribute name ""ŁOOPBACK"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_method.py b/tests/functional/n/non_ascii_name/non_ascii_name_class_method.py deleted file mode 100644 index ec05b4cf961..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_method.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Non ASCII char in classmethod""" - - -class OkayClass: - """We need a class docstring?""" - - def public(self): - """Say something""" - print(self) - - @classmethod - def umlaut_ä(cls): # [non-ascii-name] - """do something""" - return "ä" - - -# Usage should not raise a second error -OkayClass.umlaut_ä() diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_class_method.txt b/tests/functional/n/non_ascii_name/non_ascii_name_class_method.txt deleted file mode 100644 index b645bb3f199..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_class_method.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:12:4:14:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_dict_kwargs.py b/tests/functional/n/non_ascii_name/non_ascii_name_dict_kwargs.py deleted file mode 100644 index 5d7b4c7f373..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_dict_kwargs.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -We don't expect this to give any errors! -""" - - -def okay(**kwargs): - """print kwargs""" - print(kwargs) - - -keyword_args = {"łol": "this would be hard to check against"} - -okay(**keyword_args) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.py b/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.py deleted file mode 100644 index 59585645a70..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.py +++ /dev/null @@ -1,14 +0,0 @@ -"""invalid ascii char in a for loop""" - -import os - - -def main(): - """main func""" - # +2: [non-ascii-name] - a_variable = "" - for łol in os.listdir("."): - # Usage should not raise a second error - a_variable += ( - f"{łol} " - ) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.txt b/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.txt deleted file mode 100644 index 1320b15089e..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_for_loop.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:10:8:10:12:main:"Variable name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function.py b/tests/functional/n/non_ascii_name/non_ascii_name_function.py deleted file mode 100644 index e3c558ea652..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function.py +++ /dev/null @@ -1,19 +0,0 @@ -"""invalid ASCII char in a function definition""" -# pylint: disable=invalid-name - - -def sayHello(): - """Greetings""" - print("Hello, World!") - - -# +3: [non-ascii-name] - - -def sayНello(): - """From Russia with Love""" - print("Goodbye, World!") - - -# Usage should not raise a second error -sayНello() diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function.txt b/tests/functional/n/non_ascii_name/non_ascii_name_function.txt deleted file mode 100644 index f793dcbde24..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:13:0:15:28:sayНello:"Function name ""sayНello"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.py b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.py deleted file mode 100644 index 377bf865e6b..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -non ascii variable defined in a function -""" - - -def okay( - just_some_thing_long_again: str, - lol_very_long_argument: str, - łol: str, # [non-ascii-name] -) -> bool: - """Be okay, yeah?""" - # Usage should not raise a second error - print(just_some_thing_long_again, lol_very_long_argument, łol) - return True - - -# Usage should raise a second error -okay( - "A VVVVVVVEEEERRRRRRRRRRYYYYYYYYYY LONG TIME ", - lol_very_long_argument="a", - łol="b", # [non-ascii-name] -) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.rc b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.rc deleted file mode 100644 index 67a28a36aa5..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -max_pyver=3.8 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.txt b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.txt deleted file mode 100644 index 9866b040c0e..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py37minus.txt +++ /dev/null @@ -1,2 +0,0 @@ -non-ascii-name:9:4:9:13:okay:"Argument name ""łol"" contains a non-ASCII character":HIGH -non-ascii-name:21:4:21:12::"Argument name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.py b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.py deleted file mode 100644 index 377bf865e6b..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -non ascii variable defined in a function -""" - - -def okay( - just_some_thing_long_again: str, - lol_very_long_argument: str, - łol: str, # [non-ascii-name] -) -> bool: - """Be okay, yeah?""" - # Usage should not raise a second error - print(just_some_thing_long_again, lol_very_long_argument, łol) - return True - - -# Usage should raise a second error -okay( - "A VVVVVVVEEEERRRRRRRRRRYYYYYYYYYY LONG TIME ", - lol_very_long_argument="a", - łol="b", # [non-ascii-name] -) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.rc b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.rc deleted file mode 100644 index 16b75eea755..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.9 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.txt b/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.txt deleted file mode 100644 index 9866b040c0e..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_function_argument_py39plus.txt +++ /dev/null @@ -1,2 +0,0 @@ -non-ascii-name:9:4:9:13:okay:"Argument name ""łol"" contains a non-ASCII character":HIGH -non-ascii-name:21:4:21:12::"Argument name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_import_as.py b/tests/functional/n/non_ascii_name/non_ascii_name_import_as.py deleted file mode 100644 index 1803151d486..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_import_as.py +++ /dev/null @@ -1,6 +0,0 @@ -"""import non ascii alias""" -import os.path as łos # [non-ascii-name] - - -# Usage should not raise a second error -foo = łos.join("a", "b") diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_import_as.txt b/tests/functional/n/non_ascii_name/non_ascii_name_import_as.txt deleted file mode 100644 index 50226cb44c4..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_import_as.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:2:0:2:22::"Module name ""łos"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.py b/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.py deleted file mode 100644 index a17c28665fe..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.py +++ /dev/null @@ -1,6 +0,0 @@ -"""import as non ascii alias""" -from os.path import join as łos # [non-ascii-name] - - -# Usage should not raise a second error -foo = łos("a", "b") diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.txt b/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.txt deleted file mode 100644 index c8346a76df8..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_import_from_as.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:2:0:2:32::"Module name ""łos"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.py b/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.py deleted file mode 100644 index 2d47e58c2d1..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.py +++ /dev/null @@ -1,8 +0,0 @@ -"""inline loop non ascii variable definition""" -import os - - -foo = [ - f"{łol} " - for łol in os.listdir(".") # [non-ascii-name] -] diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.txt b/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.txt deleted file mode 100644 index 90219a29356..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_inline_var.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:7:8:7:12::"Variable name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.py b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.py deleted file mode 100644 index fbd382f41db..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -Defining non ASCII variables in a function call -""" - - -def okay(**kwargs): - """Print kwargs""" - print(kwargs) - - -okay( - a_long_attribute_that_is_very_okay=1, - b_belongs_to_yet_another_okay_attributed=2, - łol=3, # [non-ascii-name] -) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.rc b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.rc deleted file mode 100644 index 67a28a36aa5..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -max_pyver=3.8 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.txt b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.txt deleted file mode 100644 index b588a1b8046..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py37minus.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:14:4:14:10::"Argument name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.py b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.py deleted file mode 100644 index fbd382f41db..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -Defining non ASCII variables in a function call -""" - - -def okay(**kwargs): - """Print kwargs""" - print(kwargs) - - -okay( - a_long_attribute_that_is_very_okay=1, - b_belongs_to_yet_another_okay_attributed=2, - łol=3, # [non-ascii-name] -) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.rc b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.rc deleted file mode 100644 index 16b75eea755..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.9 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.txt b/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.txt deleted file mode 100644 index b588a1b8046..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_kwargs_py39plus.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:14:4:14:10::"Argument name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_local.py b/tests/functional/n/non_ascii_name/non_ascii_name_local.py deleted file mode 100644 index 99423fdc8f8..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_local.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Using non ascii variables in local""" - - -def okay(): - """docstring""" - łol = "foo" # [non-ascii-name] - # Usage should not raise a second error - baring = łol - print(baring) diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_local.txt b/tests/functional/n/non_ascii_name/non_ascii_name_local.txt deleted file mode 100644 index d26b0999f82..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_local.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:6:4:6:8:okay:"Variable name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py b/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py deleted file mode 100644 index e6a2b80d857..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -Test for names within keyword and position only function -""" -# pylint: disable=unused-argument - - -def name( - some_thing_long_but_okay, - not_okay_łol, # [non-ascii-name] - not_okay_defaułt=None, # [non-ascii-name] - /, - p_or_kw_okay=None, - p_or_kw_not_økay=None, # [non-ascii-name] - *, - kw_arg_okay, - kw_arg_not_økay, # [non-ascii-name] -): - """ - Do something! - """ - return "Foobar" diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.rc b/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.rc deleted file mode 100644 index 85fc502b372..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.8 diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.txt b/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.txt deleted file mode 100644 index ced7a401ee3..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.txt +++ /dev/null @@ -1,4 +0,0 @@ -non-ascii-name:9:4:9:17:name:"Argument name ""not_okay_łol"" contains a non-ASCII character":HIGH -non-ascii-name:10:4:10:21:name:"Argument name ""not_okay_defaułt"" contains a non-ASCII character":HIGH -non-ascii-name:13:4:13:21:name:"Argument name ""p_or_kw_not_økay"" contains a non-ASCII character":HIGH -non-ascii-name:16:4:16:20:name:"Argument name ""kw_arg_not_økay"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.py b/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.py deleted file mode 100644 index 9b10f1cd46b..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.py +++ /dev/null @@ -1,17 +0,0 @@ -"""static method with non ascii characters""" - - -class OkayClass: - """Class Docstring""" - - def public(self): - """Say it load""" - - @staticmethod - def umlaut_ä(): # [non-ascii-name] - """Say ä""" - return "ä" - - -# Usage should not raise a second error -OkayClass.umlaut_ä() diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.txt b/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.txt deleted file mode 100644 index f4765990ba2..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_staticmethod.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:11:4:13:19:OkayClass.umlaut_ä:"Function name ""umlaut_ä"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_try_except.py b/tests/functional/n/non_ascii_name/non_ascii_name_try_except.py deleted file mode 100644 index beccf4b9a98..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_try_except.py +++ /dev/null @@ -1,11 +0,0 @@ -""" -Also variables defined in except can't contain non ascii chars -""" - - -try: - raise AttributeError("Test") - # +1: [non-ascii-name] -except AttributeError as łol: - # Usage should not raise a second error - foo = łol diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_try_except.txt b/tests/functional/n/non_ascii_name/non_ascii_name_try_except.txt deleted file mode 100644 index 002f4057bc3..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_try_except.txt +++ /dev/null @@ -1 +0,0 @@ -non-ascii-name:9:0:11:14::"Variable name ""łol"" contains a non-ASCII character":HIGH diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_variable.py b/tests/functional/n/non_ascii_name/non_ascii_name_variable.py deleted file mode 100644 index 2994dfa4752..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_variable.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -Simply variable test -""" -# pylint: disable=invalid-name - -# Test invalid variable name -łol = "Foobar" # [non-ascii-name] -# Usage should not raise a second error -łol += "-" # [non-ascii-name] diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_variable.txt b/tests/functional/n/non_ascii_name/non_ascii_name_variable.txt deleted file mode 100644 index fa3208c0a10..00000000000 --- a/tests/functional/n/non_ascii_name/non_ascii_name_variable.txt +++ /dev/null @@ -1,2 +0,0 @@ -non-ascii-name:7:0:7:4::"Variable name ""łol"" contains a non-ASCII character":HIGH -non-ascii-name:9:0:9:4::"Variable name ""łol"" contains a non-ASCII character":HIGH