Skip to content

Commit

Permalink
Merge pull request #12496 from RonnyPfannschmidt/ronny/backport-annot…
Browse files Browse the repository at this point in the history
…ations-8.2

backport annotations to 8.2
  • Loading branch information
RonnyPfannschmidt authored Jun 21, 2024
2 parents 2a75bab + cffcbdf commit 76065e5
Show file tree
Hide file tree
Showing 244 changed files with 2,040 additions and 1,824 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
3 changes: 3 additions & 0 deletions changelog/12467.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Migrated all internal type-annotations to the python3.10+ style by using the `annotations` future import.

-- by :user:`RonnyPfannschmidt`
12 changes: 10 additions & 2 deletions doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
#
# 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
from textwrap import dedent
from typing import TYPE_CHECKING

from _pytest import __version__ as version
from _pytest import __version__ as full_version


version = full_version.split("+")[0]

if TYPE_CHECKING:
import sphinx.application
Expand Down Expand Up @@ -189,6 +193,7 @@
("py:class", "SubRequest"),
("py:class", "TerminalReporter"),
("py:class", "_pytest._code.code.TerminalRepr"),
("py:class", "TerminalRepr"),
("py:class", "_pytest.fixtures.FixtureFunctionMarker"),
("py:class", "_pytest.logging.LogCaptureHandler"),
("py:class", "_pytest.mark.structures.ParameterSet"),
Expand All @@ -210,13 +215,16 @@
("py:class", "_PluggyPlugin"),
# TypeVars
("py:class", "_pytest._code.code.E"),
("py:class", "E"), # due to delayed annotation
("py:class", "_pytest.fixtures.FixtureFunction"),
("py:class", "_pytest.nodes._NodeType"),
("py:class", "_NodeType"), # due to delayed annotation
("py:class", "_pytest.python_api.E"),
("py:class", "_pytest.recwarn.T"),
("py:class", "_pytest.runner.TResult"),
("py:obj", "_pytest.fixtures.FixtureValue"),
("py:obj", "_pytest.stash.T"),
("py:class", "_ScopeName"),
]


Expand Down Expand Up @@ -455,7 +463,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

Expand Down
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ keywords = [
"test",
"unittest",
]
license = {text = "MIT"}
license = { text = "MIT" }
authors = [
{name = "Holger Krekel"},
{name = "Bruno Oliveira"},
{name = "Ronny Pfannschmidt"},
{name = "Floris Bruynooghe"},
{name = "Brianna Laugher"},
{name = "Florian Bruhin"},
{name = "Others (See AUTHORS)"},
{ name = "Holger Krekel" },
{ name = "Bruno Oliveira" },
{ name = "Ronny Pfannschmidt" },
{ name = "Floris Bruynooghe" },
{ name = "Brianna Laugher" },
{ name = "Florian Bruhin" },
{ name = "Others (See AUTHORS)" },
]
requires-python = ">=3.8"
classifiers = [
Expand Down Expand Up @@ -99,6 +99,7 @@ select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"FA100", # add future annotations
"PYI", # flake8-pyi
"UP", # pyupgrade
"RUF", # ruff
Expand Down Expand Up @@ -169,7 +170,7 @@ lines-after-imports = 2
[tool.pylint.main]
# Maximum number of characters on a single line.
max-line-length = 120
disable= [
disable = [
"abstract-method",
"arguments-differ",
"arguments-renamed",
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 76065e5

Please sign in to comment.