Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support python >= 3.8 #53

Merged
merged 9 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install pypa/build
run: >-
python -m
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_ver: [ '3.6', '3.7', '3.8', '3.9', '3.10' ]
python_ver: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_ver }}
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.cache/pypoetry/artifacts
Expand All @@ -29,10 +29,10 @@ jobs:
key: ${{ matrix.python_ver }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ matrix.python_ver }}-pip-
- uses: abatilo/actions-poetry@v2.1.5
- uses: snok/install-poetry@v1
- name: Install dependencies
run: |
poetry install --remove-untracked
poetry install --sync
- name: Lint with flake8
run: |
poetry run flake8 .
Expand All @@ -43,7 +43,9 @@ jobs:
run: |
poetry run pytest tests --cov flake8_force_keyword_arguments --cov-config pyproject.toml --cov-report xml
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: true
flags: "${{ matrix.python_ver }}"
8 changes: 2 additions & 6 deletions flake8_force_keyword_arguments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import sys

if sys.version_info < (3, 8):
from typing_extensions import Final
from importlib_metadata import version
else:
from typing import Final
from importlib.metadata import version
from typing import Final
from importlib.metadata import version

__version__: Final[str] = version(__name__)

Expand Down
36 changes: 14 additions & 22 deletions flake8_force_keyword_arguments/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
import sys
from argparse import Namespace
from itertools import chain
from typing import ClassVar, Iterable, Tuple, Type

from flake8.options.manager import OptionManager
from marisa_trie import Trie
from typing import ClassVar, Final, Iterable, Tuple, Type

import flake8_force_keyword_arguments
from flake8.options.manager import OptionManager
from flake8_force_keyword_arguments import util

if sys.version_info < (3, 8):
from typing_extensions import Final
else:
from typing import Final
from marisa_trie import Trie

if sys.version_info < (3, 9):
from typing import Pattern
Expand All @@ -39,9 +33,9 @@
class Checker:
name: Final[str] = flake8_force_keyword_arguments.__name__
version: Final[str] = flake8_force_keyword_arguments.__version__
MESSAGE_TEMPLATE: Final[
str
] = 'FKA100 {function_name}\'s call uses {number_of_args} positional arguments, use keyword arguments.'
MESSAGE_TEMPLATE: Final[str] = (
'FKA100 {function_name}\'s call uses {number_of_args} positional arguments, use keyword arguments.'
)

_max_pos_args: ClassVar[int] = DEFAULT_MAX_POS_ARGS
_ignore_patterns: ClassVar[Tuple[Pattern[str], ...]] = ()
Expand Down Expand Up @@ -101,7 +95,7 @@ def add_options(cls, parser: OptionManager) -> None:
'--kwargs-inspect-qualifier-option',
type=util.QualifierOption,
dest='inspect_qualifier_option',
choices=tuple(map(lambda v: v.value, util.QualifierOption.__members__.values())),
choices=tuple(v.value for v in util.QualifierOption.__members__.values()),
default=DEFAULT_QUALIFIER_OPTION.value,
parse_from_config=True,
help=(
Expand All @@ -124,15 +118,13 @@ def parse_options(cls, options: Namespace) -> None:

cls._ignore_trie = Trie(
chain.from_iterable(
map(
lambda module_name: util.list_pos_only_callables(
m=importlib.import_module(module_name),
parent_module_qualifier=module_name,
poa_threshold=cls._max_pos_args,
qualifier_option=qualifier_option,
),
chain(options.inspect_module, options.inspect_module_extend),
util.list_pos_only_callables(
m=importlib.import_module(module_name),
parent_module_qualifier=module_name,
poa_threshold=cls._max_pos_args,
qualifier_option=qualifier_option,
)
for module_name in chain(options.inspect_module, options.inspect_module_extend)
)
)

Expand All @@ -144,7 +136,7 @@ def run(self) -> Iterable[Tuple[int, int, str, Type['Checker']]]:
invocation_line = util.get_invocation_line(node)

# ignored because of patterns
if any(map(lambda p: p.search(invocation_line), self._ignore_patterns)):
if any(p.search(invocation_line) for p in self._ignore_patterns):
continue

# ignored because of inspection
Expand Down
8 changes: 4 additions & 4 deletions flake8_force_keyword_arguments/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def does_callable_have_poa_more_than(o: object, poa_threshold: int) -> bool:
for p in params:
if p.kind is inspect.Parameter.VAR_POSITIONAL:
return True
elif p.kind is inspect.Parameter.POSITIONAL_ONLY:
if p.kind is inspect.Parameter.POSITIONAL_ONLY:
poa_count += 1

return poa_count >= poa_threshold
Expand Down Expand Up @@ -121,9 +121,9 @@ def dfs(a: ast.AST) -> str:
name = getattr(a, 'id', getattr(a, 'attr', None))

if child is None or not isinstance(child, ast.AST):
if name is None or not isinstance(name, str):
return ''
return name
if isinstance(name, str):
return name
return ''

return '.'.join(filter(None, (dfs(child), name)))

Expand Down
49 changes: 23 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "flake8-force-keyword-arguments"
version = "1.0.4"
version = "2.0.0"
description = "A flake8 extension that is looking for function calls and forces to use keyword arguments if there are more than X arguments"
authors = ["Viktor Chaptsev <viktor@chaptsev.ru>", "Byeonghoon Yoo <bh322yoo@gmail.com>"]
maintainers = ["Byeonghoon Yoo <bh322yoo@gmail.com>"]
Expand All @@ -15,11 +15,11 @@ classifiers = [
"Intended Audience :: Developers",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
Expand All @@ -28,31 +28,28 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.6.2"
flake8 = ">=3.8"
importlib-metadata = { version = "*", python = "<3.8" }
typing-extensions = {version = "*", python = "<3.8"}
marisa-trie = "^0.7.7"
python = "^3.8.1"
flake8 = ">5"
marisa-trie = "^1"

[tool.poetry.dev-dependencies]
pytest = "^7.0.0"
mypy = "^0.961"
flake8 = ">=3.8"
black = "^22.1"
flake8-annotations-complexity = "^0.0.6"
flake8-bandit = "^2.1.2"
flake8-black = "^0.3.1"
pytest = "^8"
mypy = "^1"
black = "^24"
flake8-annotations-complexity = "^0.0.8"
flake8-bandit = "^4.1.1"
flake8-black = "^0.3.6"
flake8-breakpoint = "^1.1.0"
flake8-bugbear = "^22.1.11"
flake8-builtins = "^1.5.3"
flake8-comprehensions = "^3.7.0"
flake8-eradicate = "^1.2.0"
flake8-functions = { version = "^0.0.7", python = "^3.7" }
flake8-print = "^4.0.0"
flake8-pytest-style = "^1.5.0"
flake8-return = "^1.1.3"
pytest-flake8-path = "^1.1.0"
pytest-cov = "^3.0.0"
flake8-bugbear = "^24.2.6"
flake8-builtins = "^2.2.0"
flake8-comprehensions = "^3.14.0"
flake8-eradicate = "^1.5.0"
flake8-functions = "^0.0.8"
flake8-print = "^5.0.0"
flake8-pytest-style = "^1.7.2"
flake8-return = "^1.2.0"
pytest-flake8-path = "^1.5.0"
pytest-cov = "^4.1.0"

[tool.poetry.plugins."flake8.extension"]
FKA1 = "flake8_force_keyword_arguments:Checker"
Expand All @@ -66,7 +63,7 @@ build-backend = "poetry.core.masonry.api"
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ["py36", "py37", "py38", "py39"]
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.mypy]
allow_redefinition = true
Expand Down
14 changes: 13 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ per-file-ignores =

max-line-length = 120
require-code = True
min-version = 3.6.2
min-version = 3.8.0

# flake8-functions
max-parameters-amount = 10
Expand All @@ -21,3 +21,15 @@ max-returns-amount = 6

kwargs-inspect-module-extend = functools,itertools
kwargs-ignore-function-pattern-extend = ^pytest.mark.parametrize$

[tox:tox]
min_version = 4.0
isolated_build = True
env_list = py{38,39,310,311,312}

[testenv]
allowlist_externals = poetry
commands =
poetry install
poetry run pytest

8 changes: 1 addition & 7 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
import sys
from functools import partial
from textwrap import dedent
from typing import Set
from typing import Final, Set

import pytest

from flake8_force_keyword_arguments import util

if sys.version_info < (3, 8):
from typing_extensions import Final
else:
from typing import Final


@pytest.mark.parametrize(
('source_code', 'expected'),
Expand Down