Skip to content

Commit 2125b49

Browse files
committed
pre-commit: Add ty for Python type hints
1 parent 1bd049c commit 2125b49

5 files changed

Lines changed: 453 additions & 307 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://beta.ruff.rs
2-
name: ruff
2+
name: ruff_and_ty
33
on:
44
push:
55
branches:
@@ -8,9 +8,11 @@ on:
88
branches:
99
- master
1010
jobs:
11-
ruff:
11+
ruff_and_ty:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v7
1515
- uses: astral-sh/setup-uv@v7
16-
- run: uvx ruff check --output-format=github .
16+
- run: uvx ruff check --output-format=github
17+
- run: uv sync
18+
- run: uv run --with=beautifulsoup4,pytest,ty ty check --output-format=github

.pre-commit-config.yaml

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ci:
22
autoupdate_schedule: monthly
33
# uv-lock resolves dependencies from PyPI, but pre-commit.ci runs hooks with no
44
# network access, so it fails there. Skip it on pre-commit.ci; it still runs locally.
5-
skip: [uv-lock]
5+
skip: [ty, uv-lock]
66

77
repos:
88
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -28,16 +28,27 @@ repos:
2828
additional_dependencies:
2929
- tomli
3030

31+
- repo: https://github.com/tox-dev/pyproject-fmt
32+
rev: v2.29.3
33+
hooks:
34+
- id: pyproject-fmt
35+
3136
- repo: https://github.com/astral-sh/ruff-pre-commit
3237
rev: v0.16.5
3338
hooks:
3439
- id: ruff-check
3540
- id: ruff-format
3641

37-
- repo: https://github.com/tox-dev/pyproject-fmt
38-
rev: v2.28.1
42+
- repo: https://github.com/astral-sh/ty-pre-commit
43+
rev: v0.0.78
3944
hooks:
40-
- id: pyproject-fmt
45+
- id: ty
46+
args: [--python, python3]
47+
48+
- repo: https://github.com/astral-sh/uv-pre-commit
49+
rev: 0.12.9
50+
hooks:
51+
- id: uv-lock
4152

4253
- repo: local
4354
hooks:
@@ -47,26 +58,11 @@ repos:
4758
language: script
4859
pass_filenames: false
4960

50-
- repo: https://github.com/astral-sh/uv-pre-commit
51-
rev: 0.12.7
52-
hooks:
53-
- id: uv-lock
54-
5561
- repo: https://github.com/abravalheri/validate-pyproject
5662
rev: "0.26"
5763
hooks:
5864
- id: validate-pyproject
5965

60-
# - repo: https://github.com/pre-commit/mirrors-mypy
61-
# rev: v1.20.0
62-
# hooks:
63-
# - id: mypy
64-
# args:
65-
# - --explicit-package-bases
66-
# - --ignore-missing-imports
67-
# - --install-types
68-
# - --non-interactive
69-
7066
- repo: https://github.com/pre-commit/mirrors-prettier
7167
rev: v4.0.0-alpha.8
7268
hooks:

neural_network/input_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import gzip
2121
import os
2222
import typing
23-
import urllib
23+
from urllib.request import urlretrieve
2424

2525
import numpy as np
2626
from tensorflow.python.framework import dtypes, random_seed
@@ -259,7 +259,7 @@ def _maybe_download(filename, work_directory, source_url):
259259
gfile.MakeDirs(work_directory)
260260
filepath = os.path.join(work_directory, filename)
261261
if not gfile.Exists(filepath):
262-
urllib.request.urlretrieve(source_url, filepath) # noqa: S310
262+
urlretrieve(source_url, filepath) # noqa: S310
263263
with gfile.GFile(filepath) as f:
264264
size = f.size()
265265
print("Successfully downloaded", filename, size, "bytes.")

pyproject.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ lint.pylint.max-returns = 8 # default: 6
175175
lint.pylint.max-statements = 88 # default: 50
176176

177177
[tool.codespell]
178-
ignore-words-list = "3rt,abd,aer,ans,bitap,crate,damon,fo,followings,hist,iff,kwanza,manuel,mater,secant,som,sur,tim,toi,zar"
178+
ignore-words-list = """\
179+
3rt,abd,aer,ans,bitap,crate,damon,fo,followings,hist,iff,kwanza,manuel,mater,secant,som,sur,tim,toi,zar\
180+
"""
179181
skip = """\
180182
./.*,*.json,*.lock,ciphers/prehistoric_men.txt,project_euler/problem_022/p022_names.txt,pyproject.toml,strings/dictio\
181183
nary.txt,strings/words.txt\
@@ -184,6 +186,23 @@ skip = """\
184186
[tool.mypy]
185187
python_version = "3.14"
186188

189+
[tool.ty]
190+
rules.call-non-callable = "ignore"
191+
rules.deprecated = "ignore"
192+
rules.invalid-argument-type = "ignore"
193+
rules.invalid-assignment = "ignore"
194+
rules.invalid-parameter-default = "ignore"
195+
rules.invalid-return-type = "ignore"
196+
rules.invalid-type-arguments = "ignore"
197+
rules.invalid-type-form = "ignore"
198+
rules.no-matching-overload = "ignore"
199+
rules.not-iterable = "ignore"
200+
rules.not-subscriptable = "ignore"
201+
rules.parameter-already-assigned = "ignore"
202+
rules.unresolved-attribute = "ignore"
203+
rules.unresolved-import = "ignore"
204+
rules.unsupported-operator = "ignore"
205+
187206
[tool.pytest]
188207
ini_options.addopts = [
189208
"--durations=10",

0 commit comments

Comments
 (0)