Skip to content

Commit 9295f9f

Browse files
RFC: from __future__ import annotations + migrate
1 parent 20dd1d6 commit 9295f9f

File tree

242 files changed

+1961
-1777
lines changed

Some content is hidden

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

242 files changed

+1961
-1777
lines changed

bench/bench.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import sys
24

35

bench/bench_argcomplete.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# 2.7.5 3.3.2
33
# FilesCompleter 75.1109 69.2116
44
# FastFilesCompleter 0.7383 1.0760
5+
from __future__ import annotations
6+
57
import timeit
68

79

bench/empty.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
from __future__ import annotations
2+
3+
14
for i in range(1000):
25
exec("def test_func_%d(): pass" % i)

bench/manyparam.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

bench/skip.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

bench/unit_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from unittest import TestCase # noqa: F401
24

35

bench/xunit.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
for i in range(5000):
25
exec(
36
f"""

doc/en/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
# The full version, including alpha/beta/rc tags.
1717
# The short X.Y version.
18+
from __future__ import annotations
19+
1820
import os
1921
from pathlib import Path
2022
import shutil
@@ -455,7 +457,7 @@
455457
}
456458

457459

458-
def setup(app: "sphinx.application.Sphinx") -> None:
460+
def setup(app: sphinx.application.Sphinx) -> None:
459461
app.add_crossref_type(
460462
"fixture",
461463
"fixture",

doc/en/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
from __future__ import annotations
2+
3+
14
collect_ignore = ["conf.py"]

doc/en/example/assertion/failure_demo.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24
from pytest import raises
35

doc/en/example/assertion/global_testmodule_config/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os.path
24

35
import pytest

doc/en/example/assertion/global_testmodule_config/test_hello_world.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
hello = "world"
25

36

doc/en/example/assertion/test_failures.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os.path
24
import shutil
35

doc/en/example/assertion/test_setup_flow_example.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
def setup_module(module):
25
module.TestStateFullThing.classcount = 0
36

doc/en/example/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
from __future__ import annotations
2+
3+
14
collect_ignore = ["nonpython", "customdirectory"]

doc/en/example/customdirectory/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# content of conftest.py
2+
from __future__ import annotations
3+
24
import json
35

46
import pytest
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# content of test_first.py
2+
from __future__ import annotations
3+
4+
25
def test_1():
36
pass
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# content of test_second.py
2+
from __future__ import annotations
3+
4+
25
def test_2():
36
pass
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# content of test_third.py
2+
from __future__ import annotations
3+
4+
25
def test_3():
36
pass

doc/en/example/fixtures/test_fixtures_order_autouse.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/fixtures/test_fixtures_order_autouse_multiple_scopes.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/fixtures/test_fixtures_order_autouse_temp_effects.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/fixtures/test_fixtures_order_dependencies.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/fixtures/test_fixtures_order_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/fixtures/test_fixtures_request_different_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

doc/en/example/multipython.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Module containing a parametrized tests testing cross-python serialization
22
via the pickle module."""
33

4+
from __future__ import annotations
5+
46
import shutil
57
import subprocess
68
import textwrap

doc/en/example/nonpython/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# content of conftest.py
2+
from __future__ import annotations
3+
24
import pytest
35

46

doc/en/example/pythoncollection.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# run this with $ pytest --collect-only test_collectonly.py
22
#
3+
from __future__ import annotations
34

45

56
def test_function():

doc/en/example/xfail_demo.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35

extra/get_issues.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
from pathlib import Path
35
import sys

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ lint.select = [
9898
"D", # pydocstyle
9999
"E", # pycodestyle
100100
"F", # pyflakes
101+
"FA100", # add future annotations
101102
"I", # isort
102103
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
103104
"PIE", # flake8-pie
@@ -155,6 +156,10 @@ lint.per-file-ignores."src/_pytest/_version.py" = [
155156
lint.per-file-ignores."testing/python/approx.py" = [
156157
"B015",
157158
]
159+
lint.extend-safe-fixes = [
160+
"UP006",
161+
"UP007",
162+
]
158163
lint.isort.combine-as-imports = true
159164
lint.isort.force-single-line = true
160165
lint.isort.force-sort-within-sections = true
@@ -164,9 +169,13 @@ lint.isort.known-local-folder = [
164169
]
165170
lint.isort.lines-after-imports = 2
166171
lint.isort.order-by-type = false
172+
lint.isort.required-imports = [
173+
"from __future__ import annotations",
174+
]
167175
# In order to be able to format for 88 char in ruff format
168176
lint.pycodestyle.max-line-length = 120
169177
lint.pydocstyle.convention = "pep257"
178+
lint.pyupgrade.keep-runtime-typing = false
170179

171180
[tool.pylint.main]
172181
# Maximum number of characters on a single line.

scripts/generate-gh-release-notes.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Requires Python3.6+.
1010
"""
1111

12+
from __future__ import annotations
13+
1214
from pathlib import Path
1315
import re
1416
import sys

scripts/prepare-release-pr.py

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
`pytest bot <[email protected]>` commit author.
1515
"""
1616

17+
from __future__ import annotations
18+
1719
import argparse
1820
from pathlib import Path
1921
import re

scripts/release.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# mypy: disallow-untyped-defs
22
"""Invoke development tasks."""
33

4+
from __future__ import annotations
5+
46
import argparse
57
import os
68
from pathlib import Path

scripts/update-plugin-list.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# mypy: disallow-untyped-defs
2+
from __future__ import annotations
3+
24
import datetime
35
import pathlib
46
import re

src/_pytest/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__all__ = ["__version__", "version_tuple"]
25

36
try:

src/_pytest/_argcomplete.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
global argcomplete script).
6363
"""
6464

65+
from __future__ import annotations
66+
6567
import argparse
6668
from glob import glob
6769
import os
6870
import sys
6971
from typing import Any
70-
from typing import List
71-
from typing import Optional
7272

7373

7474
class FastFilesCompleter:
@@ -77,7 +77,7 @@ class FastFilesCompleter:
7777
def __init__(self, directories: bool = True) -> None:
7878
self.directories = directories
7979

80-
def __call__(self, prefix: str, **kwargs: Any) -> List[str]:
80+
def __call__(self, prefix: str, **kwargs: Any) -> list[str]:
8181
# Only called on non option completions.
8282
if os.sep in prefix[1:]:
8383
prefix_dir = len(os.path.dirname(prefix) + os.sep)
@@ -104,7 +104,7 @@ def __call__(self, prefix: str, **kwargs: Any) -> List[str]:
104104
import argcomplete.completers
105105
except ImportError:
106106
sys.exit(-1)
107-
filescompleter: Optional[FastFilesCompleter] = FastFilesCompleter()
107+
filescompleter: FastFilesCompleter | None = FastFilesCompleter()
108108

109109
def try_argcomplete(parser: argparse.ArgumentParser) -> None:
110110
argcomplete.autocomplete(parser, always_complete_options=False)

src/_pytest/_code/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Python inspection/code generation API."""
22

3+
from __future__ import annotations
4+
35
from .code import Code
46
from .code import ExceptionInfo
57
from .code import filter_traceback

0 commit comments

Comments
 (0)