Skip to content

Commit 2eac84a

Browse files
committed
Init repository
0 parents  commit 2eac84a

18 files changed

+813
-0
lines changed

.github/dependabot.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
labels:
8+
- "dependency"
9+
open-pull-requests-limit: 10
10+
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"
15+
labels:
16+
- "dependency"
17+
open-pull-requests-limit: 10

.gitignore

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Python template
2+
# https://github.com/github/gitignore/blob/master/Python.gitignore
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
101+
__pypackages__/
102+
103+
# Celery stuff
104+
celerybeat-schedule
105+
celerybeat.pid
106+
107+
# SageMath parsed files
108+
*.sage.py
109+
110+
# Environments
111+
.env
112+
.venv
113+
env/
114+
venv/
115+
ENV/
116+
env.bak/
117+
venv.bak/
118+
119+
# Spyder project settings
120+
.spyderproject
121+
.spyproject
122+
123+
# Rope project settings
124+
.ropeproject
125+
126+
# mkdocs documentation
127+
/site
128+
129+
# mypy
130+
.mypy_cache/
131+
.dmypy.json
132+
dmypy.json
133+
134+
# Pyre type checker
135+
.pyre/
136+
137+
# pytype static type analyzer
138+
.pytype/
139+
140+
# Cython debug symbols
141+
cython_debug/
142+
143+
144+
# -----
145+
# VisualStudioCode template
146+
# https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore
147+
148+
.vscode/*
149+
!.vscode/tasks.json
150+
!.vscode/launch.json
151+
!.vscode/extensions.json
152+
!.vscode/settings.json
153+
*.code-workspace
154+
155+
# Local History for Visual Studio Code
156+
.history/
157+
158+
159+
# -----
160+
# macOS template (partial)
161+
# https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
162+
163+
# General
164+
.DS_Store
165+
.AppleDouble
166+
.LSOverride
167+
168+
169+
# -----
170+
# Windows template (partial)
171+
# https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
172+
173+
# Windows thumbnail cache files
174+
Thumbs.db
175+
176+
# Folder config file
177+
[Dd]esktop.ini
178+
179+
180+
# -----
181+
# Custom / Overwrites
182+
.vscode/settings.json

.pre-commit-hooks.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- id: python-typing-update
2+
name: Update Python typing
3+
description: Update Python typing syntax
4+
entry: python-typing-update
5+
require_serial: true
6+
language: python
7+
types: [python]
8+
minimum_pre_commit_version: 0.15.0

.vscode/extensions.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": [
7+
"ms-python.python",
8+
"ms-python.vscode-pylance",
9+
"visualstudioexptteam.vscodeintellicode",
10+
"littlefoxteam.vscode-python-test-adapter",
11+
"streetsidesoftware.code-spell-checker",
12+
],
13+
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
14+
"unwantedRecommendations": [
15+
16+
]
17+
}

.vscode/settings.default.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"editor.tabSize": 4,
3+
"editor.insertSpaces": true,
4+
"files.trimFinalNewlines": true,
5+
"files.insertFinalNewline": true,
6+
"[markdown]": {
7+
"files.trimTrailingWhitespace": false
8+
},
9+
"[yaml]": {
10+
"editor.insertSpaces": true,
11+
"editor.tabSize": 2,
12+
"editor.autoIndent": "advanced"
13+
}
14+
}

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marc Mueller <cdce8p>

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Marc Mueller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Python typing update
2+
3+
Small tool to update Python typing syntax.
4+
It uses
5+
- [python-reorder-imports][pri]
6+
- [pyupgrade][pyu]
7+
- [isort][isort]
8+
- [autoflake][autoflake]
9+
- [black][black]
10+
- git
11+
12+
to try and update the typing syntax the best it can.
13+
14+
**Important**
15+
Since every project uses a different formatting style,
16+
always check `git diff` before committing any changes!
17+
Since this tool uses [pyupgrade][pyu], it's best used for
18+
projects that use it already.
19+
20+
21+
## Limitations
22+
Due to the way the tool works, it will reorder the imports multiple times.
23+
By default the tool tries to detect if a comment was moved
24+
and revert all changes to the file. This can be overwritten by using `--force`.
25+
26+
27+
## How it works
28+
1. Run [python-reorder-import][pri] to add
29+
`from __future__ import annotations` to each file.
30+
2. Run [pyupgrade][pyu] to use generic aliases ([PEP 585][PEP585])
31+
and alternative union syntax ([PEP 604][PEP604]) where possible.
32+
3. Run [autoflake][autoflake] to check if any typing import is now
33+
unused. If not, revert changes with `git restore`.
34+
4. Remove unused imports with [autoflake][autoflake].
35+
5. Run [isort][isort] to try to restore the previous formatting.
36+
6. Optional: Run [black][black]
37+
7. Check `git diff` for modified comments.
38+
If one is detected, revert changes and print file name.
39+
Can be overwritten with `--force`.
40+
41+
42+
## Setup pre-commit
43+
44+
Add this to the `.pre-commit-config.yaml` file
45+
46+
```yaml
47+
repos:
48+
- repo: https://github.com/cdce8p/python-typing-update
49+
rev: <insert current tag here!>
50+
hooks:
51+
- id: python-typing-update
52+
stages: [manual]
53+
```
54+
55+
Run with
56+
```bash
57+
pre-commit run --hook-stage manual python-typing-update --all-files
58+
```
59+
60+
## Configuration
61+
62+
**`--verbose`**
63+
Always print verbose logging.
64+
65+
**`--full-reorder`**
66+
Use additional options from [python-reorder-imports][pri] to rewrite
67+
- `--py38-plus` (default): Imports from `mypy_extensions` and `typing_extensions` when possible.
68+
- `--py39-plus`: Rewrite [PEP 585][PEP585] typing imports. Additionally `typing.Hashable` and `typing.Sized` will also be replace by their `collections.abc` equivalents.
69+
70+
**`--black`**
71+
Run `black` formatting after updates.
72+
73+
**`--check`**
74+
Check if files would be modified. Return with exitcode `1` or `0` if not. Useful for CI runs.
75+
76+
**`--force`**
77+
Don't revert changes if a modified comment is detected.
78+
Check `git diff` before committing!
79+
80+
**`--py39-plus`**
81+
Set the minimum Python syntax to **3.9**. (Default: **3.8**)
82+
83+
**`--py310-plus`**
84+
Set the minimum Python syntax to **3.10**. (Default: **3.10**)
85+
86+
87+
## License
88+
This Project is licensed under the MIT license.
89+
See [LICENSE](LICENSE) for the full license text.
90+
91+
92+
[pri]: https://github.com/asottile/reorder_python_imports
93+
[pyu]: https://github.com/asottile/pyupgrade
94+
[isort]: https://github.com/PyCQA/isort
95+
[autoflake]: https://github.com/myint/autoflake
96+
[black]: https://github.com/psf/black
97+
[PEP585]: https://www.python.org/dev/peps/pep-0585/
98+
[PEP604]: https://www.python.org/dev/peps/pep-0604/

pylintrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[MASTER]
2+
ignore=
3+
4+
[BASIC]
5+
good-names=
6+
i,j,k,_,fp,it,ex,logger
7+
8+
[MESSAGE CONTROL]
9+
# Reasons disabled:
10+
# superfluous-parens - used with :=
11+
# duplicate-code - for scripts acceptable
12+
disable=
13+
superfluous-parens,
14+
missing-module-docstring,
15+
missing-class-docstring,
16+
missing-function-docstring,
17+
too-many-instance-attributes,
18+
too-many-return-statements,
19+
too-many-locals,
20+
too-many-branches,
21+
too-many-statements,
22+
too-many-arguments,
23+
too-few-public-methods,
24+
invalid-name,
25+
duplicate-code,
26+
27+
[FORMAT]
28+
max-line-length=119
29+
30+
[REPORTS]
31+
score = false

python_typing_update/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)