Skip to content

Commit

Permalink
Merge pull request #1633 from PyCQA/py37-plus
Browse files Browse the repository at this point in the history
require python>=3.7
  • Loading branch information
asottile committed Aug 28, 2022
2 parents e249dc4 + e94fb10 commit a929f12
Show file tree
Hide file tree
Showing 76 changed files with 337 additions and 263 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
- os: ubuntu-latest
python: pypy-3.7
toxenv: py
- os: ubuntu-latest
python: 3.6
toxenv: py
- os: ubuntu-latest
python: 3.7
toxenv: py
Expand All @@ -32,7 +29,7 @@ jobs:
toxenv: py
# windows
- os: windows-latest
python: 3.6
python: 3.7
toxenv: py
# misc
- os: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ repos:
rev: v3.8.2
hooks:
- id: reorder-python-imports
args: [--application-directories, '.:src', --py36-plus]
args: [
--application-directories, '.:src',
--py37-plus,
--add-import, 'from __future__ import annotations',
]
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
Expand Down
14 changes: 8 additions & 6 deletions bin/gen-pycodestyle-plugin
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
from __future__ import annotations

import inspect
import os.path
from typing import Any
from typing import Callable
from typing import Generator
from typing import NamedTuple
from typing import Tuple

import pycodestyle

Expand All @@ -20,7 +21,7 @@ def _too_long(s: str) -> str:
class Call(NamedTuple):
name: str
is_generator: bool
params: Tuple[str, ...]
params: tuple[str, ...]

def to_src(self) -> str:
params_s = ", ".join(self.params)
Expand All @@ -35,7 +36,7 @@ class Call(NamedTuple):
return "\n".join(lines)

@classmethod
def from_func(cls, func: Callable[..., Any]) -> "Call":
def from_func(cls, func: Callable[..., Any]) -> Call:
spec = inspect.getfullargspec(func)
params = tuple(spec.args)
return cls(func.__name__, inspect.isgeneratorfunction(func), params)
Expand All @@ -55,9 +56,10 @@ def lines() -> Generator[str, None, None]:

yield f'"""Generated using ./bin/{os.path.basename(__file__)}."""'
yield "# fmt: off"
yield "from __future__ import annotations"
yield ""
yield "from typing import Any"
yield "from typing import Generator"
yield "from typing import Tuple"
yield ""
imports = sorted(call.name for call in logical + physical)
for name in imports:
Expand All @@ -69,7 +71,7 @@ def lines() -> Generator[str, None, None]:
logical_params = {param for call in logical for param in call.params}
for param in sorted(logical_params):
yield f" {param}: Any,"
yield ") -> Generator[Tuple[int, str], None, None]:"
yield ") -> Generator[tuple[int, str], None, None]:"
yield ' """Run pycodestyle logical checks."""'
for call in sorted(logical):
yield call.to_src()
Expand All @@ -80,7 +82,7 @@ def lines() -> Generator[str, None, None]:
physical_params = {param for call in physical for param in call.params}
for param in sorted(physical_params):
yield f" {param}: Any,"
yield ") -> Generator[Tuple[int, str], None, None]:"
yield ") -> Generator[tuple[int, str], None, None]:"
yield ' """Run pycodestyle physical checks."""'
for call in sorted(physical):
yield call.to_src()
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))
from __future__ import annotations

import flake8

# -- General configuration ------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions example-plugin/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import setuptools

setuptools.setup(
Expand Down
2 changes: 2 additions & 0 deletions example-plugin/src/flake8_example_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Module for an example Flake8 plugin."""
from __future__ import annotations

from .off_by_default import ExampleTwo
from .on_by_default import ExampleOne

Expand Down
1 change: 1 addition & 0 deletions example-plugin/src/flake8_example_plugin/off_by_default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Our first example plugin."""
from __future__ import annotations


class ExampleTwo:
Expand Down
1 change: 1 addition & 0 deletions example-plugin/src/flake8_example_plugin/on_by_default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Our first example plugin."""
from __future__ import annotations


class ExampleOne:
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -43,7 +42,7 @@ install_requires =
pycodestyle>=2.9.0,<2.10.0
pyflakes>=2.5.0,<2.6.0
importlib-metadata>=1.1.0,<4.3;python_version<"3.8"
python_requires = >=3.6.1
python_requires = >=3.7

[options.packages.find]
where = src
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Packaging logic for Flake8."""
from __future__ import annotations

import os
import sys

Expand Down
8 changes: 4 additions & 4 deletions src/flake8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
.. autofunction:: flake8.configure_logging
"""
from __future__ import annotations

import logging
import sys
from typing import Optional
from typing import Type

LOG = logging.getLogger(__name__)
LOG.addHandler(logging.NullHandler())
Expand All @@ -35,7 +35,7 @@

def configure_logging(
verbosity: int,
filename: Optional[str] = None,
filename: str | None = None,
logformat: str = LOG_FORMAT,
) -> None:
"""Configure logging for flake8.
Expand All @@ -56,7 +56,7 @@ def configure_logging(

if not filename or filename in ("stderr", "stdout"):
fileobj = getattr(sys, filename or "stderr")
handler_cls: Type[logging.Handler] = logging.StreamHandler
handler_cls: type[logging.Handler] = logging.StreamHandler
else:
fileobj = filename
handler_cls = logging.FileHandler
Expand Down
2 changes: 2 additions & 0 deletions src/flake8/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Module allowing for ``python -m flake8 ...``."""
from __future__ import annotations

from flake8.main.cli import main

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions src/flake8/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Expose backports in a single place."""
from __future__ import annotations

import sys

if sys.version_info >= (3, 8): # pragma: no cover (PY38+)
Expand Down
1 change: 1 addition & 0 deletions src/flake8/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
This is the only submodule in Flake8 with a guaranteed stable API. All other
submodules are considered internal only and are subject to change.
"""
from __future__ import annotations
21 changes: 10 additions & 11 deletions src/flake8/api/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
Previously, users would import :func:`get_style_guide` from ``flake8.engine``.
In 3.0 we no longer have an "engine" module but we maintain the API from it.
"""
from __future__ import annotations

import argparse
import logging
import os.path
from typing import Any
from typing import List
from typing import Optional
from typing import Type

import flake8
from flake8.discover_files import expand_paths
Expand Down Expand Up @@ -53,7 +52,7 @@ def total_errors(self) -> int:
"""Return the total number of errors."""
return self._application.result_count

def get_statistics(self, violation: str) -> List[str]:
def get_statistics(self, violation: str) -> list[str]:
"""Get the list of occurrences of a violation.
:returns:
Expand Down Expand Up @@ -97,12 +96,12 @@ def options(self) -> argparse.Namespace:
return self._application.options

@property
def paths(self) -> List[str]:
def paths(self) -> list[str]:
"""Return the extra arguments passed as paths."""
assert self._application.options is not None
return self._application.options.filenames

def check_files(self, paths: Optional[List[str]] = None) -> Report:
def check_files(self, paths: list[str] | None = None) -> Report:
"""Run collected checks on the files provided.
This will check the files passed in and return a :class:`Report`
Expand All @@ -119,7 +118,7 @@ def check_files(self, paths: Optional[List[str]] = None) -> Report:
self._application.report_errors()
return Report(self._application)

def excluded(self, filename: str, parent: Optional[str] = None) -> bool:
def excluded(self, filename: str, parent: str | None = None) -> bool:
"""Determine if a file is excluded.
:param filename:
Expand Down Expand Up @@ -148,7 +147,7 @@ def excluded(path: str) -> bool:

def init_report(
self,
reporter: Optional[Type[formatter.BaseFormatter]] = None,
reporter: type[formatter.BaseFormatter] | None = None,
) -> None:
"""Set up a formatter for this run of Flake8."""
if reporter is None:
Expand All @@ -170,9 +169,9 @@ def init_report(
def input_file(
self,
filename: str,
lines: Optional[Any] = None,
expected: Optional[Any] = None,
line_offset: Optional[Any] = 0,
lines: Any | None = None,
expected: Any | None = None,
line_offset: Any | None = 0,
) -> Report:
"""Run collected checks on a single file.
Expand Down

0 comments on commit a929f12

Please sign in to comment.