diff options
author | RSTdefg <34202999+RSTdefg@users.noreply.github.com> | 2023-04-12 07:58:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 13:58:35 +0200 |
commit | 0cd41b1fb15e31eb311b61f93bc27f7cacc2f7ac (patch) | |
tree | 5e7b519837b8e841deee49586d744cc672dc83b1 /pylint | |
parent | 1a1452a8b2478cd748a270ef238af47d61f02141 (diff) | |
download | pylint-git-0cd41b1fb15e31eb311b61f93bc27f7cacc2f7ac.tar.gz |
Fix `unused-import` to check`dummy-variables-rgx` (#8566)
Resolve #8500
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/variables.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 8647cc8a6..cad4c76ea 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -3055,6 +3055,13 @@ class VariablesChecker(BaseChecker): imported_name in self._type_annotation_names or as_name in self._type_annotation_names ) + + is_dummy_import = ( + as_name + and self.linter.config.dummy_variables_rgx + and self.linter.config.dummy_variables_rgx.match(as_name) + ) + if isinstance(stmt, nodes.Import) or ( isinstance(stmt, nodes.ImportFrom) and not stmt.modname ): @@ -3065,12 +3072,11 @@ class VariablesChecker(BaseChecker): # because they can be imported for exporting. continue - if is_type_annotation_import: + if is_type_annotation_import or is_dummy_import: # Most likely a typing import if it wasn't used so far. + # Also filter dummy variables. continue - if as_name == "_": - continue if as_name is None: msg = f"import {imported_name}" else: @@ -3088,8 +3094,9 @@ class VariablesChecker(BaseChecker): # __future__ import in another module. continue - if is_type_annotation_import: + if is_type_annotation_import or is_dummy_import: # Most likely a typing import if it wasn't used so far. + # Also filter dummy variables. continue if imported_name == "*": |