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

RFC: from __future__ import annotations + pyupgrade #10997

Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ pip-wheel-metadata/

# pytest debug logs generated via --debug
pytestdebug.log
/.dmypy.json
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py38-plus]
args: ['--application-directories=.:src', --py38-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
Expand Down
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

if __name__ == "__main__":
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

imports = [
Expand Down
2 changes: 2 additions & 0 deletions bench/empty.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
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

SKIP = True
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

for i in range(15000):
Expand Down
2 changes: 2 additions & 0 deletions bench/xunit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

for i in range(5000):
exec(
f"""
Expand Down
6 changes: 4 additions & 2 deletions 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
import shutil
import sys
Expand Down Expand Up @@ -438,7 +440,7 @@
}


def configure_logging(app: "sphinx.application.Sphinx") -> None:
RonnyPfannschmidt marked this conversation as resolved.
Show resolved Hide resolved
def configure_logging(app: sphinx.application.Sphinx) -> None:
"""Configure Sphinx's WarningHandler to handle (expected) missing include."""
import sphinx.util.logging
import logging
Expand All @@ -461,7 +463,7 @@ def filter(self, record: logging.LogRecord) -> bool:
warn_handler[0].filters.insert(0, WarnLogFilter())


def setup(app: "sphinx.application.Sphinx") -> None:
def setup(app: sphinx.application.Sphinx) -> None:
app.add_crossref_type(
"fixture",
"fixture",
Expand Down
2 changes: 2 additions & 0 deletions doc/en/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
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,5 @@
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
2 changes: 2 additions & 0 deletions doc/en/example/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
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,5 +1,7 @@
"""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

xfail = pytest.mark.xfail
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
2 changes: 2 additions & 0 deletions scripts/generate-gh-release-notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

Requires Python3.6+.
"""
from __future__ import annotations

import re
import sys
from pathlib import Path
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 @@ -13,6 +13,8 @@
**Token**: currently the token from the GitHub Actions is used, pushed with
`pytest bot <[email protected]>` commit author.
"""
from __future__ import annotations

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

import argparse
import os
from pathlib import Path
Expand Down
5 changes: 4 additions & 1 deletion scripts/towncrier-draft-to-file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# mypy: disallow-untyped-defs
from __future__ import annotations

import sys
from subprocess import call

# mypy: disallow-untyped-defs


def main() -> int:
"""
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
2 changes: 2 additions & 0 deletions src/_pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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 @@ -61,13 +61,13 @@
which should throw a KeyError: 'COMPLINE' (which is properly set by the
global argcomplete script).
"""
from __future__ import annotations

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


class FastFilesCompleter:
Expand All @@ -76,7 +76,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 @@ -103,7 +103,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,4 +1,6 @@
"""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