diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b4cc9d57e8b2..d643e06737c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,9 @@ repos: + - repo: https://github.com/hadialqattan/pycln + rev: v2.0.2 # must match requirements-tests.txt + hooks: + - id: pycln + args: [--all, stubs, stdlib, tests, scripts] - repo: https://github.com/psf/black rev: 22.6.0 # must match requirements-tests.txt hooks: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ca0e61d281c..54354cca8d40 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ it takes a bit longer. For more details, read below. Typeshed runs continuous integration (CI) on all pull requests. This means that if you file a pull request (PR), our full test suite -- including our linter, `flake8` -- is run on your PR. It also means that bots will automatically apply -changes to your PR (using `black` and `isort`) to fix any formatting issues. +changes to your PR (using `pycln`, `black` and `isort`) to fix any formatting issues. This frees you up to ignore all local setup on your side, focus on the code and rely on the CI to fix everything, or point you to the places that need fixing. @@ -82,7 +82,8 @@ terminal to install all non-pytype requirements: ## Code formatting -The code is formatted using `black` and `isort`. +The code is formatted using `black` and `isort`. Unused imports are also +auto-removed using `pycln`. The repository is equipped with a [`pre-commit.ci`](https://pre-commit.ci/) configuration file. This means that you don't *need* to do anything yourself to @@ -90,9 +91,10 @@ run the code formatters. When you push a commit, a bot will run those for you right away and add a commit to your PR. That being said, if you *want* to run the checks locally when you commit, -you're free to do so. Either run `black` and `isort` manually... +you're free to do so. Either run `pycln`, `black` and `isort` manually... ``` +pycln --all . isort . black . ``` diff --git a/requirements-tests.txt b/requirements-tests.txt index 3bca1ca471c6..0b27f50025b1 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -9,5 +9,6 @@ flake8-pyi==22.5.1 # must match .pre-commit-config.yaml isort==5.10.1 tomli==1.2.2 +pycln==2.0.2 packaging==21.3 termcolor diff --git a/stdlib/tokenize.pyi b/stdlib/tokenize.pyi index 5ca0d2cd4e58..1a67736e78de 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -1,6 +1,5 @@ import sys from _typeshed import StrOrBytesPath -from builtins import open as _builtin_open from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern from token import * diff --git a/stdlib/unittest/loader.pyi b/stdlib/unittest/loader.pyi index 73b25c7495d1..9ba04b084c7f 100644 --- a/stdlib/unittest/loader.pyi +++ b/stdlib/unittest/loader.pyi @@ -1,5 +1,4 @@ import unittest.case -import unittest.result import unittest.suite from collections.abc import Callable, Sequence from re import Pattern diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 0abdd736ec5c..7e3f63e02fc4 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -6,7 +6,9 @@ from os import stat_result from typing import Any, overload from typing_extensions import TypeAlias -from . import ospath as path +from . import ospath + +path = ospath _FdOrAnyPath: TypeAlias = int | StrOrBytesPath