Skip to content

Commit

Permalink
RFC: from __future__ import annotations + migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Jun 20, 2024
1 parent 20dd1d6 commit 9295f9f
Show file tree
Hide file tree
Showing 242 changed files with 1,961 additions and 1,777 deletions.
2 changes: 2 additions & 0 deletions bench/bench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys


Expand Down
2 changes: 2 additions & 0 deletions bench/bench_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# 2.7.5 3.3.2
# FilesCompleter 75.1109 69.2116
# FastFilesCompleter 0.7383 1.0760
from __future__ import annotations

import timeit


Expand Down
3 changes: 3 additions & 0 deletions bench/empty.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import annotations


for i in range(1000):
exec("def test_func_%d(): pass" % i)
2 changes: 2 additions & 0 deletions bench/manyparam.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions bench/skip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions bench/unit_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import TestCase # noqa: F401


Expand Down
3 changes: 3 additions & 0 deletions bench/xunit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


for i in range(5000):
exec(
f"""
Expand Down
4 changes: 3 additions & 1 deletion doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# The full version, including alpha/beta/rc tags.
# The short X.Y version.
from __future__ import annotations

import os
from pathlib import Path
import shutil
Expand Down Expand Up @@ -455,7 +457,7 @@
}


def setup(app: "sphinx.application.Sphinx") -> None:
def setup(app: sphinx.application.Sphinx) -> None:
app.add_crossref_type(
"fixture",
"fixture",
Expand Down
3 changes: 3 additions & 0 deletions doc/en/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


collect_ignore = ["conf.py"]
2 changes: 2 additions & 0 deletions doc/en/example/assertion/failure_demo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest
from pytest import raises

Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/assertion/global_testmodule_config/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path

import pytest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


hello = "world"


Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/assertion/test_failures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path
import shutil

Expand Down
3 changes: 3 additions & 0 deletions doc/en/example/assertion/test_setup_flow_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def setup_module(module):
module.TestStateFullThing.classcount = 0

Expand Down
3 changes: 3 additions & 0 deletions doc/en/example/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


collect_ignore = ["nonpython", "customdirectory"]
2 changes: 2 additions & 0 deletions doc/en/example/customdirectory/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# content of conftest.py
from __future__ import annotations

import json

import pytest
Expand Down
3 changes: 3 additions & 0 deletions doc/en/example/customdirectory/tests/test_first.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# content of test_first.py
from __future__ import annotations


def test_1():
pass
3 changes: 3 additions & 0 deletions doc/en/example/customdirectory/tests/test_second.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# content of test_second.py
from __future__ import annotations


def test_2():
pass
3 changes: 3 additions & 0 deletions doc/en/example/customdirectory/tests/test_third.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# content of test_third.py
from __future__ import annotations


def test_3():
pass
2 changes: 2 additions & 0 deletions doc/en/example/fixtures/test_fixtures_order_autouse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/fixtures/test_fixtures_order_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/fixtures/test_fixtures_order_scope.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/multipython.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Module containing a parametrized tests testing cross-python serialization
via the pickle module."""

from __future__ import annotations

import shutil
import subprocess
import textwrap
Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/nonpython/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# content of conftest.py
from __future__ import annotations

import pytest


Expand Down
1 change: 1 addition & 0 deletions doc/en/example/pythoncollection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# run this with $ pytest --collect-only test_collectonly.py
#
from __future__ import annotations


def test_function():
Expand Down
2 changes: 2 additions & 0 deletions doc/en/example/xfail_demo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions extra/get_issues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
from pathlib import Path
import sys
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ lint.select = [
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"FA100", # add future annotations
"I", # isort
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
"PIE", # flake8-pie
Expand Down Expand Up @@ -155,6 +156,10 @@ lint.per-file-ignores."src/_pytest/_version.py" = [
lint.per-file-ignores."testing/python/approx.py" = [
"B015",
]
lint.extend-safe-fixes = [
"UP006",
"UP007",
]
lint.isort.combine-as-imports = true
lint.isort.force-single-line = true
lint.isort.force-sort-within-sections = true
Expand All @@ -164,9 +169,13 @@ lint.isort.known-local-folder = [
]
lint.isort.lines-after-imports = 2
lint.isort.order-by-type = false
lint.isort.required-imports = [
"from __future__ import annotations",
]
# In order to be able to format for 88 char in ruff format
lint.pycodestyle.max-line-length = 120
lint.pydocstyle.convention = "pep257"
lint.pyupgrade.keep-runtime-typing = false

[tool.pylint.main]
# Maximum number of characters on a single line.
Expand Down
2 changes: 2 additions & 0 deletions scripts/generate-gh-release-notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
Requires Python3.6+.
"""

from __future__ import annotations

from pathlib import Path
import re
import sys
Expand Down
2 changes: 2 additions & 0 deletions scripts/prepare-release-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
`pytest bot <[email protected]>` commit author.
"""

from __future__ import annotations

import argparse
from pathlib import Path
import re
Expand Down
2 changes: 2 additions & 0 deletions scripts/release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# mypy: disallow-untyped-defs
"""Invoke development tasks."""

from __future__ import annotations

import argparse
import os
from pathlib import Path
Expand Down
2 changes: 2 additions & 0 deletions scripts/update-plugin-list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# mypy: disallow-untyped-defs
from __future__ import annotations

import datetime
import pathlib
import re
Expand Down
3 changes: 3 additions & 0 deletions src/_pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


__all__ = ["__version__", "version_tuple"]

try:
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
global argcomplete script).
"""

from __future__ import annotations

import argparse
from glob import glob
import os
import sys
from typing import Any
from typing import List
from typing import Optional


class FastFilesCompleter:
Expand All @@ -77,7 +77,7 @@ class FastFilesCompleter:
def __init__(self, directories: bool = True) -> None:
self.directories = directories

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

def try_argcomplete(parser: argparse.ArgumentParser) -> None:
argcomplete.autocomplete(parser, always_complete_options=False)
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Python inspection/code generation API."""

from __future__ import annotations

from .code import Code
from .code import ExceptionInfo
from .code import filter_traceback
Expand Down
Loading

0 comments on commit 9295f9f

Please sign in to comment.