Merge pull request #1748 from PyCQA/upgrade-pyflakes

upgrade pyflakes to 3.0.0
This commit is contained in:
Anthony Sottile 2022-11-23 13:59:50 -05:00 committed by GitHub
commit b5cac8790f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 17 deletions

View file

@ -36,7 +36,7 @@ package_dir =
install_requires = install_requires =
mccabe>=0.7.0,<0.8.0 mccabe>=0.7.0,<0.8.0
pycodestyle>=2.10.0,<2.11.0 pycodestyle>=2.10.0,<2.11.0
pyflakes>=2.5.0,<2.6.0 pyflakes>=3.0.0,<3.1.0
# 3.8.0's importlib.metadata is broken # 3.8.0's importlib.metadata is broken
python_requires = >=3.8.1 python_requires = >=3.8.1

View file

@ -4,7 +4,6 @@ from __future__ import annotations
import argparse import argparse
import ast import ast
import os import os
import tokenize
from typing import Any from typing import Any
from typing import Generator from typing import Generator
@ -52,13 +51,13 @@ FLAKE8_PYFLAKES_CODES = {
"DefaultExceptNotLast": "F707", "DefaultExceptNotLast": "F707",
"DoctestSyntaxError": "F721", "DoctestSyntaxError": "F721",
"ForwardAnnotationSyntaxError": "F722", "ForwardAnnotationSyntaxError": "F722",
"CommentAnnotationSyntaxError": "F723",
"RedefinedWhileUnused": "F811", "RedefinedWhileUnused": "F811",
"UndefinedName": "F821", "UndefinedName": "F821",
"UndefinedExport": "F822", "UndefinedExport": "F822",
"UndefinedLocal": "F823", "UndefinedLocal": "F823",
"DuplicateArgument": "F831", "DuplicateArgument": "F831",
"UnusedVariable": "F841", "UnusedVariable": "F841",
"UnusedAnnotation": "F842",
"RaiseNotImplemented": "F901", "RaiseNotImplemented": "F901",
} }
@ -70,12 +69,7 @@ class FlakesChecker(pyflakes.checker.Checker):
include_in_doctest: list[str] = [] include_in_doctest: list[str] = []
exclude_from_doctest: list[str] = [] exclude_from_doctest: list[str] = []
def __init__( def __init__(self, tree: ast.AST, filename: str) -> None:
self,
tree: ast.AST,
file_tokens: list[tokenize.TokenInfo],
filename: str,
) -> None:
"""Initialize the PyFlakes plugin with an AST tree and filename.""" """Initialize the PyFlakes plugin with an AST tree and filename."""
filename = utils.normalize_path(filename) filename = utils.normalize_path(filename)
with_doctest = self.with_doctest with_doctest = self.with_doctest
@ -99,12 +93,7 @@ class FlakesChecker(pyflakes.checker.Checker):
if overlapped_by: if overlapped_by:
with_doctest = True with_doctest = True
super().__init__( super().__init__(tree, filename=filename, withDoctest=with_doctest)
tree,
filename=filename,
withDoctest=with_doctest,
file_tokens=file_tokens,
)
@classmethod @classmethod
def add_options(cls, parser: OptionManager) -> None: def add_options(cls, parser: OptionManager) -> None:

View file

@ -685,7 +685,7 @@ def test_load_plugin_ok():
assert loaded == finder.LoadedPlugin( assert loaded == finder.LoadedPlugin(
plugin, plugin,
FlakesChecker, FlakesChecker,
{"tree": True, "file_tokens": True, "filename": True}, {"tree": True, "filename": True},
) )

View file

@ -27,7 +27,7 @@ def f():
sys = sys sys = sys
""" """
tree = ast.parse(src) tree = ast.parse(src)
checker = pyflakes_shim.FlakesChecker(tree, [], "t.py") checker = pyflakes_shim.FlakesChecker(tree, "t.py")
message_texts = [s for _, _, s, _ in checker.run()] message_texts = [s for _, _, s, _ in checker.run()]
assert message_texts == [ assert message_texts == [
"F823 local variable 'sys' defined in enclosing scope on line 1 referenced before assignment", # noqa: E501 "F823 local variable 'sys' defined in enclosing scope on line 1 referenced before assignment", # noqa: E501