Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from __future__ import annotations + migrate #12467

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt this results in the |release| RST substitution having the value of 8.2 which might have a weird perception in changelog draft titles: https://docs.pytest.org/en/8.2.x/changelog.html#to-be-included-in-vrelease-if-present / https://docs.pytest.org/en/latest/changelog.html#to-be-included-in-vrelease-if-present.

Should this be something like +dev in the end but without a variable component, something static? Though, perhaps in RTD it'd be okay to use the long original version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I cut off too much

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I cut off too much


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
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 <pytestbot@gmail.com>` 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