Skip to content

Commit

Permalink
Ensure modern type annotation best practices and modern syntax (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored May 28, 2024
1 parent fe5cd1e commit 11fda91
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev']
architecture: ['x64', 'x86']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
architecture: ["x64", "x86"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12-dev']
python-version: ["3.10", "3.11", "3.12-dev"]

steps:
- uses: actions/checkout@v4
Expand All @@ -75,7 +75,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
architecture: "x64"
cache: pip
cache-dependency-path: .github/workflows/main.yml

Expand Down Expand Up @@ -107,14 +107,14 @@ jobs:
- uses: actions/setup-python@v5
with:
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
python-version: '3.8'
python-version: "3.8"
cache: pip
cache-dependency-path: .github/workflows/main.yml
- run: pip install pycln
- run: pycln . --config=pycln.toml --check
- uses: chartboost/ruff-action@v1
with:
version: '0.3.7'
version: "0.4.5"
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand All @@ -125,7 +125,7 @@ jobs:
fail-fast: false
matrix:
# mypy 1.5 dropped support for Python 3.7
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -141,7 +141,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
args: [--config=pycln.toml]
verbose: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
rev: v0.4.5
hooks:
- id: ruff # Run the linter.
args: [--fix]
Expand Down
11 changes: 10 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ target-version = "py37"

[lint]
select = [
"I", # isort
"I", # isort
"PLC", # Pylint Convention
# Ensure modern type annotation syntax and best practices
# Not including those covered by type-checkers
"FA", # flake8-future-annotations
"F404", # late-future-import
"PYI", # flake8-pyi
"UP006", # non-pep585-annotation
"UP007", # non-pep604-annotation
"UP010", # unnecessary-future-import
"UP037", # quoted-annotation
]

[lint.per-file-ignores]
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from tempfile import gettempdir
from typing import Iterable, List, Tuple, Union
from typing import Iterable

from distutils import ccompiler
from distutils._msvccompiler import MSVCCompiler
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def finalize_options(self):
swig_include_files = "mapilib adsilib".split()


def expand_modules(module_dir: Union[str, os.PathLike[str]]):
def expand_modules(module_dir: str | os.PathLike[str]):
"""Helper to allow our script specifications to include wildcards."""
return [str(path.with_suffix("")) for path in Path(module_dir).rglob("*.py")]

Expand All @@ -2100,7 +2100,7 @@ def expand_modules(module_dir: Union[str, os.PathLike[str]]):
# 'Lib/site-packages/pythonwin/licence.txt'. We exploit this to
# get 'com/win32com/whatever' installed to 'win32com/whatever'
def convert_data_files(files: Iterable[str]):
ret: List[Tuple[str, Tuple[str]]] = []
ret: list[tuple[str, tuple[str]]] = []
for file in files:
file = os.path.normpath(file)
if file.find("*") >= 0:
Expand Down
3 changes: 2 additions & 1 deletion win32/Lib/win32gui_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@

def _MakeResult(names_str, values):
names = names_str.split()
nt = namedtuple(names[0], names[1:])
# TODO: Dynamic namedtuple. This could be made static, also exposing the types
nt = namedtuple(names[0], names[1:]) # noqa: PYI024
return nt(*values)


Expand Down

0 comments on commit 11fda91

Please sign in to comment.