Skip to content

[WIP] py36 plus #7811

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

Closed
wants to merge 6 commits into from
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
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ repos:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.7.0
rev: v1.8.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.10b0]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -21,31 +21,31 @@ repos:
exclude: _pytest/(debugging|hookspec).py
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.2
rev: 3.8.3
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-typing-imports==1.9.0
- flake8-docstrings==1.5.0
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.0
rev: v2.3.5
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py3-plus]
args: ['--application-directories=.:src', --py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.4.4
rev: v2.7.2
hooks:
- id: pyupgrade
args: [--py3-plus]
args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.9.0
rev: v1.11.0
hooks:
- id: setup-cfg-fmt
# TODO: when upgrading setup-cfg-fmt this can be removed
args: [--max-py-version=3.9]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.780 # NOTE: keep this in sync with setup.cfg.
rev: v0.782 # NOTE: keep this in sync with setup.cfg.
hooks:
- id: mypy
files: ^(src/|testing/)
Expand Down
1 change: 1 addition & 0 deletions changelog/5196.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests are now ordered by definition order in more cases.
2 changes: 1 addition & 1 deletion changelog/7808.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest now supports python3.6+ only.
pytest now supports python3.6.1+ only.
2 changes: 1 addition & 1 deletion doc/en/example/assertion/failure_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_tupleerror(self):

def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
items = [1, 2, 3]
print("items is {!r}".format(items))
print(f"items is {items!r}")
a, b = items.pop()

def test_some_error(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def pytest_runtest_setup(item):
return
mod = item.getparent(pytest.Module).obj
if hasattr(mod, "hello"):
print("mod.hello {!r}".format(mod.hello))
print(f"mod.hello {mod.hello!r}")
4 changes: 2 additions & 2 deletions doc/en/example/multipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Python:
def __init__(self, version, picklefile):
self.pythonpath = shutil.which(version)
if not self.pythonpath:
pytest.skip("{!r} not found".format(version))
pytest.skip(f"{version!r} not found")
self.picklefile = picklefile

def dumps(self, obj):
Expand Down Expand Up @@ -69,4 +69,4 @@ def load_and_is_true(self, expression):
@pytest.mark.parametrize("obj", [42, {}, {1: 3}])
def test_basic_objects(python1, python2, obj):
python1.dumps(obj)
python2.load_and_is_true("obj == {}".format(obj))
python2.load_and_is_true(f"obj == {obj}")
2 changes: 1 addition & 1 deletion doc/en/example/nonpython/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def repr_failure(self, excinfo):
)

def reportinfo(self):
return self.fspath, 0, "usecase: {}".format(self.name)
return self.fspath, 0, f"usecase: {self.name}"


class YamlException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ template = "changelog/_template.rst"
showcontent = true

[tool.black]
target-version = ['py35']
target-version = ['py36']
16 changes: 5 additions & 11 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def announce(version):
stdout = stdout.decode("utf-8")
last_version = stdout.strip()

stdout = check_output(
["git", "log", "{}..HEAD".format(last_version), "--format=%aN"]
)
stdout = check_output(["git", "log", f"{last_version}..HEAD", "--format=%aN"])
stdout = stdout.decode("utf-8")

contributors = set(stdout.splitlines())
Expand All @@ -31,14 +29,10 @@ def announce(version):
Path(__file__).parent.joinpath(template_name).read_text(encoding="UTF-8")
)

contributors_text = (
"\n".join("* {}".format(name) for name in sorted(contributors)) + "\n"
)
contributors_text = "\n".join(f"* {name}" for name in sorted(contributors)) + "\n"
text = template_text.format(version=version, contributors=contributors_text)

target = Path(__file__).parent.joinpath(
"../doc/en/announce/release-{}.rst".format(version)
)
target = Path(__file__).parent.joinpath(f"../doc/en/announce/release-{version}.rst")
target.write_text(text, encoding="UTF-8")
print(f"{Fore.CYAN}[generate.announce] {Fore.RESET}Generated {target.name}")

Expand All @@ -47,7 +41,7 @@ def announce(version):
lines = index_path.read_text(encoding="UTF-8").splitlines()
indent = " "
for index, line in enumerate(lines):
if line.startswith("{}release-".format(indent)):
if line.startswith(f"{indent}release-"):
new_line = indent + target.stem
if line != new_line:
lines.insert(index, new_line)
Expand Down Expand Up @@ -96,7 +90,7 @@ def pre_release(version, *, skip_check_links):
if not skip_check_links:
check_links()

msg = "Prepare release version {}".format(version)
msg = f"Prepare release version {version}"
check_call(["git", "commit", "-a", "-m", msg])

print()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ install_requires =
atomicwrites>=1.0;sys_platform=="win32"
colorama;sys_platform=="win32"
importlib-metadata>=0.12;python_version<"3.8"
python_requires = >=3.6
python_requires = >=3.6.1
package_dir =
=src
setup_requires =
Expand Down
22 changes: 10 additions & 12 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from inspect import CO_VARARGS
from inspect import CO_VARKEYWORDS
from io import StringIO
from pathlib import Path
from traceback import format_exception_only
from types import CodeType
from types import FrameType
Expand All @@ -17,6 +18,7 @@
from typing import List
from typing import Mapping
from typing import Optional
from typing import overload
from typing import Pattern
from typing import Sequence
from typing import Set
Expand All @@ -41,8 +43,6 @@
from _pytest._io.saferepr import saferepr
from _pytest.compat import final
from _pytest.compat import get_real_func
from _pytest.compat import overload
from _pytest.pathlib import Path

if TYPE_CHECKING:
from typing_extensions import Literal
Expand All @@ -58,7 +58,7 @@ def __init__(self, rawcode) -> None:
if not hasattr(rawcode, "co_filename"):
rawcode = getrawcode(rawcode)
if not isinstance(rawcode, CodeType):
raise TypeError("not a code object: {!r}".format(rawcode))
raise TypeError(f"not a code object: {rawcode!r}")
self.filename = rawcode.co_filename
self.firstlineno = rawcode.co_firstlineno - 1
self.name = rawcode.co_name
Expand Down Expand Up @@ -346,13 +346,11 @@ def cut(
def __getitem__(self, key: int) -> TracebackEntry:
...

@overload # noqa: F811
def __getitem__(self, key: slice) -> "Traceback": # noqa: F811
@overload
def __getitem__(self, key: slice) -> "Traceback":
...

def __getitem__( # noqa: F811
self, key: Union[int, slice]
) -> Union[TracebackEntry, "Traceback"]:
def __getitem__(self, key: Union[int, slice]) -> Union[TracebackEntry, "Traceback"]:
if isinstance(key, slice):
return self.__class__(super().__getitem__(key))
else:
Expand Down Expand Up @@ -749,7 +747,7 @@ def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
else:
str_repr = safeformat(value)
# if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)):
lines.append("{:<10} = {}".format(name, str_repr))
lines.append(f"{name:<10} = {str_repr}")
# else:
# self._line("%-10s =\\" % (name,))
# # XXX
Expand Down Expand Up @@ -1058,7 +1056,7 @@ def _write_entry_lines(self, tw: TerminalWriter) -> None:
# separate indents and source lines that are not failures: we want to
# highlight the code but not the indentation, which may contain markers
# such as "> assert 0"
fail_marker = "{} ".format(FormattedExcinfo.fail_marker)
fail_marker = f"{FormattedExcinfo.fail_marker} "
indent_size = len(fail_marker)
indents = [] # type: List[str]
source_lines = [] # type: List[str]
Expand Down Expand Up @@ -1124,7 +1122,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
if i != -1:
msg = msg[:i]
tw.write(self.path, bold=True, red=True)
tw.line(":{}: {}".format(self.lineno, msg))
tw.line(f":{self.lineno}: {msg}")


@attr.s(eq=False)
Expand All @@ -1144,7 +1142,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
if self.args:
linesofar = ""
for name, value in self.args:
ns = "{} = {}".format(name, value)
ns = f"{name} = {value}"
if len(ns) + len(linesofar) + 2 > tw.fullwidth:
if linesofar:
tw.line(linesofar)
Expand Down
9 changes: 4 additions & 5 deletions src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from typing import Iterator
from typing import List
from typing import Optional
from typing import overload
from typing import Tuple
from typing import Union

from _pytest.compat import overload


class Source:
"""An immutable object holding a source code fragment.
Expand Down Expand Up @@ -46,11 +45,11 @@ def __eq__(self, other: object) -> bool:
def __getitem__(self, key: int) -> str:
...

@overload # noqa: F811
def __getitem__(self, key: slice) -> "Source": # noqa: F811
@overload
def __getitem__(self, key: slice) -> "Source":
...

def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: # noqa: F811
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]:
if isinstance(key, int):
return self.lines[key]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/_io/saferepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _pformat_dispatch(
width: int = 80,
depth: Optional[int] = None,
*,
compact: bool = False
compact: bool = False,
) -> str:
return AlwaysDispatchingPrettyPrinter(
indent=indent, width=width, depth=depth, compact=compact
Expand Down
6 changes: 3 additions & 3 deletions src/_pytest/_io/terminalwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def width_of_current_line(self) -> int:
def markup(self, text: str, **markup: bool) -> str:
for name in markup:
if name not in self._esctable:
raise ValueError("unknown markup: {!r}".format(name))
raise ValueError(f"unknown markup: {name!r}")
if self.hasmarkup:
esc = [self._esctable[name] for name, on in markup.items() if on]
if esc:
Expand All @@ -109,7 +109,7 @@ def sep(
sepchar: str,
title: Optional[str] = None,
fullwidth: Optional[int] = None,
**markup: bool
**markup: bool,
) -> None:
if fullwidth is None:
fullwidth = self.fullwidth
Expand All @@ -128,7 +128,7 @@ def sep(
# N <= (fullwidth - len(title) - 2) // (2*len(sepchar))
N = max((fullwidth - len(title) - 2) // (2 * len(sepchar)), 1)
fill = sepchar * N
line = "{} {} {}".format(fill, title, fill)
line = f"{fill} {title} {fill}"
else:
# we want len(sepchar)*N <= fullwidth
# i.e. N <= fullwidth // len(sepchar)
Expand Down
Loading