Skip to content

Commit bb97936

Browse files
373 add from future import annotations where possible (#375)
* Add `from __future__ import annotations` where possible * Fix broken imports * Fix pydantic model builds Don't use schema store to validate pyproject.toml * Remove `from __future__ import annotations` from typer files to try and avoid performance regression
1 parent 2c58170 commit bb97936

66 files changed

Lines changed: 317 additions & 110 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ repos:
33
rev: v0.23
44
hooks:
55
- id: validate-pyproject
6-
additional_dependencies: ["validate-pyproject-schema-store[all]"]
76
- repo: https://github.com/tox-dev/pyproject-fmt
87
rev: v2.5.0
98
hooks:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ lint.select = [
108108
]
109109
lint.ignore = [ "D417", "PLR2004", "SIM108" ]
110110
lint.per-file-ignores."tests/**/*.py" = [ "D", "INP", "S101" ]
111+
lint.flake8-type-checking.runtime-evaluated-base-classes = [ "pydantic.BaseModel" ]
111112
lint.pydocstyle.convention = "google"
112113

113114
[tool.codespell]

src/usethis/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""The CLI application for usethis."""
22

3+
from __future__ import annotations
4+
35
from usethis._app import app
46

57
app(prog_name="usethis")

src/usethis/_ci.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
from pathlib import Path
35

src/usethis/_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
from collections.abc import Generator
1+
from __future__ import annotations
2+
23
from contextlib import contextmanager
4+
from typing import TYPE_CHECKING
35

46
import typer
57
from pydantic import BaseModel
68

9+
if TYPE_CHECKING:
10+
from collections.abc import Generator
11+
712

813
class UsethisConfig(BaseModel):
914
"""Global-state for command options which affect low level behaviour."""

src/usethis/_console.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import codecs
24
import sys
35

src/usethis/_core/badge.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
from __future__ import annotations
2+
13
import re
24
from pathlib import Path
5+
from typing import TYPE_CHECKING
36

47
import typer
58
from pydantic import BaseModel
6-
from typing_extensions import Self
79

810
from usethis._console import err_print, tick_print, warn_print
911
from usethis._core.readme import add_readme, get_readme_path
10-
from usethis._integrations.pyproject_toml.errors import (
11-
PyprojectTOMLError,
12-
)
12+
from usethis._integrations.pyproject_toml.errors import PyprojectTOMLError
1313
from usethis._integrations.pyproject_toml.name import get_name
1414

15+
if TYPE_CHECKING:
16+
from typing_extensions import Self
17+
1518

1619
class Badge(BaseModel):
1720
markdown: str

src/usethis/_core/browse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import typer
24

35
from usethis._console import box_print

src/usethis/_core/ci.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from usethis._ci import update_bitbucket_pytest_steps
24
from usethis._console import box_print, info_print
35
from usethis._integrations.bitbucket.config import (

src/usethis/_core/readme.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pathlib import Path
24

35
from usethis._console import box_print, tick_print

0 commit comments

Comments
 (0)