From df9535434a1f63bb6c363575863b61da4a8c6c6d Mon Sep 17 00:00:00 2001 From: Hakan Celik Date: Sun, 24 Dec 2023 10:37:38 +0300 Subject: [PATCH] Python 3.12 support added (#312) --- .github/workflows/docs.yml | 2 +- .github/workflows/pypi.yml | 4 ++-- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docs/CHANGELOG.md | 6 ++++++ docs/CONTRIBUTING.md | 10 +++++----- pyproject.toml | 2 +- setup.cfg | 3 ++- src/unimport/__init__.py | 2 +- src/unimport/constants.py | 2 ++ .../analyzer/typing/type_parameter_syntax.py | 20 +++++++++++++++++++ .../refactor/typing/type_parameter_syntax.py | 5 +++++ .../source/typing/type_parameter_syntax.py | 6 ++++++ tests/cases/test_cases.py | 4 ++-- tox.ini | 2 +- 15 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 tests/cases/analyzer/typing/type_parameter_syntax.py create mode 100644 tests/cases/refactor/typing/type_parameter_syntax.py create mode 100644 tests/cases/source/typing/type_parameter_syntax.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f84976ba..6ee8075c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v3.5.3 - uses: actions/setup-python@v4.6.1 with: - python-version: "3.11" + python-version: "3.12" architecture: "x64" - name: Install Dependencies diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index ae4b8001..af7b6afc 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v3.5.3 - uses: actions/setup-python@v4.6.1 with: - python-version: "3.11" + python-version: "3.12" architecture: "x64" - name: Install Dependencies @@ -32,7 +32,7 @@ jobs: - uses: actions/checkout@v3.5.3 - uses: actions/setup-python@v4.6.1 with: - python-version: "3.11" + python-version: "3.12" architecture: "x64" - name: Install Dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47ede925..32be6e03 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3.5.3 diff --git a/Dockerfile b/Dockerfile index 84752705..4eca7d0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-alpine +FROM python:3.12-alpine COPY . /app WORKDIR /app diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3f95bf77..e6b48c6c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - YYYY-MM-DD +## [1.2.1] - 2023-12-24 + +### Added + +- Python 3.12 support added + ## [1.2.0] - 2023-12-22 ### Changed diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 6b03fe16..479dfc06 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -35,15 +35,15 @@ $ git rebase upstream/main ## Testing -First, make sure you have at least one of the python versions py3.8, py3.9, py3.10 and -py3.11. If not all versions are available, after opening PR, github action will run the -tests for each version, so you can be sure that you wrote the correct code. You can skip -the tox step below. +First, make sure you have at least one of the python versions py3.8, py3.9, py3.10, +py3.11 and py3.12 If not all versions are available, after opening PR, github action +will run the tests for each version, so you can be sure that you wrote the correct code. +You can skip the tox step below. After typing your codes, you should run the tests by typing the following command. ```shell -$ python3.11 -m pip install tox +$ python3.12 -m pip install tox $ tox ``` diff --git a/pyproject.toml b/pyproject.toml index 7b0fe2ea..42edd8ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ skip_gitignore = true [tool.black] line-length = 120 -target-version = ['py38', 'py39', 'py310', 'py311'] +target-version = ['py38', 'py39', 'py310', 'py311', 'py312'] [tool.unimport] include_star_import = true diff --git a/setup.cfg b/setup.cfg index a7b7e875..05dd17b3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython Environment :: Console Topic :: Software Development :: Libraries :: Python Modules @@ -31,7 +32,7 @@ project_urls = Changelog = https://unimport.hakancelik.dev/1.2.0/CHANGELOG/ [options] -python_requires = >=3.8, <3.12 +python_requires = >=3.8, <3.13 include_package_data = true zip_safe = true packages = diff --git a/src/unimport/__init__.py b/src/unimport/__init__.py index 4db71176..a5406991 100644 --- a/src/unimport/__init__.py +++ b/src/unimport/__init__.py @@ -1,2 +1,2 @@ -__version__ = "1.2.0" +__version__ = "1.2.1" __description__ = "A linter, formatter for finding and removing unused import statements." diff --git a/src/unimport/constants.py b/src/unimport/constants.py index 98239904..ffd17402 100644 --- a/src/unimport/constants.py +++ b/src/unimport/constants.py @@ -10,6 +10,7 @@ "INIT_FILE_IGNORE_REGEX", "PY39_PLUS", "PY310_PLUS", + "PY312_PLUS", "STDLIB_PATH", "SUBSCRIPT_TYPE_VARIABLE", ) @@ -27,6 +28,7 @@ # CONF PY39_PLUS = sys.version_info >= (3, 9) PY310_PLUS = sys.version_info >= (3, 10) +PY312_PLUS = sys.version_info >= (3, 12) SUBSCRIPT_TYPE_VARIABLE = frozenset( { diff --git a/tests/cases/analyzer/typing/type_parameter_syntax.py b/tests/cases/analyzer/typing/type_parameter_syntax.py new file mode 100644 index 00000000..1023843b --- /dev/null +++ b/tests/cases/analyzer/typing/type_parameter_syntax.py @@ -0,0 +1,20 @@ +from typing import List, Union + +from unimport.statement import Import, ImportFrom, Name + +__all__ = ["NAMES", "IMPORTS", "UNUSED_IMPORTS"] + + +NAMES: List[Name] = [ + Name(lineno=6, name="Point", is_all=False), + Name(lineno=6, name="tuple", is_all=False), + Name(lineno=6, name="x", is_all=False), + Name(lineno=6, name="float", is_all=False), +] +IMPORTS: List[Union[Import, ImportFrom]] = [ + Import(lineno=3, column=1, name="x", package="x"), + Import(lineno=4, column=1, name="y", package="y"), +] +UNUSED_IMPORTS: List[Union[Import, ImportFrom]] = [ + Import(lineno=4, column=1, name="y", package="y"), +] diff --git a/tests/cases/refactor/typing/type_parameter_syntax.py b/tests/cases/refactor/typing/type_parameter_syntax.py new file mode 100644 index 00000000..4a706b05 --- /dev/null +++ b/tests/cases/refactor/typing/type_parameter_syntax.py @@ -0,0 +1,5 @@ +# pytest.mark.skipif(not PY312_PLUS, reason: "type parameter syntax is supported above python 3.12") + +import x + +type Point = tuple[x, float] diff --git a/tests/cases/source/typing/type_parameter_syntax.py b/tests/cases/source/typing/type_parameter_syntax.py new file mode 100644 index 00000000..7c01a2ce --- /dev/null +++ b/tests/cases/source/typing/type_parameter_syntax.py @@ -0,0 +1,6 @@ +# pytest.mark.skipif(not PY312_PLUS, reason: "type parameter syntax is supported above python 3.12") + +import x +import y + +type Point = tuple[x, float] diff --git a/tests/cases/test_cases.py b/tests/cases/test_cases.py index cda0e8df..a80c4aba 100644 --- a/tests/cases/test_cases.py +++ b/tests/cases/test_cases.py @@ -6,7 +6,7 @@ import pytest from unimport.analyzers import MainAnalyzer -from unimport.constants import PY310_PLUS # noqa using eval expression +from unimport.constants import PY310_PLUS, PY312_PLUS # noqa using eval expression from unimport.refactor import refactor_string from unimport.statement import Import, Name from unimport.utils import list_paths @@ -32,7 +32,7 @@ def test_cases(path: Path, logger): source = path.read_text() skip_if = re.search(r"# pytest.mark.skipif\((?P.*), reason: (?P.*)\)", source, re.IGNORECASE) - if skip_if and (condition := skip_if.group("condition")) and condition in ("not PY310_PLUS",): + if skip_if and (condition := skip_if.group("condition")) and condition in ("not PY310_PLUS", "not PY312_PLUS"): reason = skip_if.group("reason") pytest.mark.skipif(False, reason, allow_module_level=True) diff --git a/tox.ini b/tox.ini index de649fb0..6ee323ce 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = 3.8, 3.9, 3.10, 3.11, pre-commit +envlist = 3.8, 3.9, 3.10, 3.11, 3.12, pre-commit isolated_build = true [testenv]