diff --git a/flake8_unused_fixtures.py b/flake8_unused_fixtures.py index 1d73195..2c53f43 100644 --- a/flake8_unused_fixtures.py +++ b/flake8_unused_fixtures.py @@ -1,8 +1,14 @@ import ast +import sys from typing import Any, Generator, List, Tuple, Type, Union import pkg_resources +if sys.version_info >= (3, 9): + from ast import unparse +else: + from astunparse import unparse + MSG = "FUF100 fixture <{}> not used" @@ -33,7 +39,7 @@ def _check_for_unused_fixtures( all_fixture_names = [ arg.arg for arg in node.args.args if arg.arg not in skip_fixtures ] - body_as_str = ast.unparse(node.body) + body_as_str = unparse(node.body) for fixture_name, fixture in zip(all_fixture_names, node.args.args): if fixture_name not in body_as_str: self.problems.append( diff --git a/poetry.lock b/poetry.lock index d6ad7bd..527df42 100644 --- a/poetry.lock +++ b/poetry.lock @@ -10,7 +10,7 @@ python-versions = "*" name = "astpretty" version = "3.0.0" description = "Pretty print the output of python stdlib `ast.parse`." -category = "main" +category = "dev" optional = false python-versions = ">=3.8" @@ -28,6 +28,17 @@ six = "*" [package.extras] test = ["astroid (<=2.5.3)", "pytest"] +[[package]] +name = "astunparse" +version = "1.6.3" +description = "An AST unparser for Python" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +six = ">=1.6.1,<2.0" + [[package]] name = "atomicwrites" version = "1.4.1" @@ -215,7 +226,7 @@ testing = ["Django (<3.1)", "colorama", "docopt", "pytest (<7.0.0)"] [[package]] name = "matplotlib-inline" -version = "0.1.3" +version = "0.1.5" description = "Inline Matplotlib backend for Jupyter" category = "dev" optional = false @@ -415,7 +426,7 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2. name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" -category = "dev" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" @@ -480,13 +491,14 @@ python-versions = "*" [metadata] lock-version = "1.1" -python-versions = "^3.8" -content-hash = "c9296341ac5c9c89c6032fe81ebba0fe5f38930fc7e4a8c936c59ad7fdedc3da" +python-versions = "^3.9" +content-hash = "41670b61962e80a7aaa74c0e0639792761bdb777a3b08950e659fb726c249c3d" [metadata.files] appnope = [] astpretty = [] asttokens = [] +astunparse = [] atomicwrites = [] attrs = [] backcall = [ @@ -516,8 +528,8 @@ jedi = [ {file = "jedi-0.18.1.tar.gz", hash = "sha256:74137626a64a99c8eb6ae5832d99b3bdd7d29a3850fe2aa80a4126b2a7d949ab"}, ] matplotlib-inline = [ - {file = "matplotlib-inline-0.1.3.tar.gz", hash = "sha256:a04bfba22e0d1395479f866853ec1ee28eea1485c1d69a6faf00dc3e24ff34ee"}, - {file = "matplotlib_inline-0.1.3-py3-none-any.whl", hash = "sha256:aed605ba3b72462d64d475a21a9296f400a19c4f74a31b59103d2a99ffd5aa5c"}, + {file = "matplotlib-inline-0.1.5.tar.gz", hash = "sha256:a728d796a1a44265b310340ef04ba8aba4e89dcb76dfdd1272becab4923dd867"}, + {file = "matplotlib_inline-0.1.5-py3-none-any.whl", hash = "sha256:a68624e181d5b272bbfbaadb44412c9d3c9ebbcb703404502b9c937afc377ff5"}, ] mccabe = [] mypy-extensions = [ diff --git a/pyproject.toml b/pyproject.toml index 70216a3..0052994 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,26 +4,29 @@ version = "0.1.1" description = "Warn about unnecesary fixtures in tests definition." authors = ["Marcin Binkowski "] repository = "https://github.com/MarcinBinkowski/flake8_unused_fixtures" -license = "BSD-2-Clause" +readme = "README.md" +license = "BSD-3-Clause" keywords = ["flake8", "lint"] classifiers=[ "Intended Audience :: Developers", "Environment :: Console", - "Programming Language :: Python :: 3.9", + "Programming Language :: Python", "Operating System :: OS Independent", "License :: OSI Approved :: BSD License", ] [tool.poetry.dependencies] -python = "^3.9" -astpretty = "^3.0.0" +python = "^3.8" flake8 = "^5.0.4" +astunparse = "^1.6.3" [tool.poetry.dev-dependencies] black = "^22.6.0" isort = "^5.10.1" pytest = "^7.1.2" ipdb = "^0.13.9" +astpretty = "^3.0.0" + [tool.isort] profile = "black"