Skip to content

A few more Python>=3.8 simplifications #11192

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

Merged
merged 1 commit into from
Jul 10, 2023
Merged
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
4 changes: 0 additions & 4 deletions doc/en/how-to/failures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ Warning about unraisable exceptions and unhandled thread exceptions

.. versionadded:: 6.2

.. note::

These features only work on Python>=3.8.

Unhandled exceptions are exceptions that are raised in a situation in which
they cannot propagate to a caller. The most common case is an exception raised
in a :meth:`__del__ <object.__del__>` implementation.
Expand Down
10 changes: 5 additions & 5 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ def __getitem__(

def filter(
self,
# TODO(py38): change to positional only.
_excinfo_or_fn: Union[
excinfo_or_fn: Union[
"ExceptionInfo[BaseException]",
Callable[[TracebackEntry], bool],
],
/,
) -> "Traceback":
"""Return a Traceback instance with certain items removed.

Expand All @@ -408,10 +408,10 @@ def filter(
``TracebackEntry`` instance, and should return True when the item should
be added to the ``Traceback``, False when not.
"""
if isinstance(_excinfo_or_fn, ExceptionInfo):
fn = lambda x: not x.ishidden(_excinfo_or_fn) # noqa: E731
if isinstance(excinfo_or_fn, ExceptionInfo):
fn = lambda x: not x.ishidden(excinfo_or_fn) # noqa: E731
else:
fn = _excinfo_or_fn
fn = excinfo_or_fn
return Traceback(filter(fn, self))

def recursionindex(self) -> Optional[int]:
Expand Down
18 changes: 0 additions & 18 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,21 +769,3 @@ def bestrelpath(directory: Path, dest: Path) -> str:
# Forward from base to dest.
*reldest.parts,
)


# Originates from py. path.local.copy(), with siginficant trims and adjustments.
# TODO(py38): Replace with shutil.copytree(..., symlinks=True, dirs_exist_ok=True)
def copytree(source: Path, target: Path) -> None:
"""Recursively copy a source directory to target."""
assert source.is_dir()
for entry in visit(source, recurse=lambda entry: not entry.is_symlink()):
x = Path(entry)
relpath = x.relative_to(source)
newx = target / relpath
newx.parent.mkdir(exist_ok=True)
if x.is_symlink():
newx.symlink_to(os.readlink(x))
elif x.is_file():
shutil.copyfile(x, newx)
elif x.is_dir():
newx.mkdir(exist_ok=True)
3 changes: 1 addition & 2 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
from _pytest.outcomes import importorskip
from _pytest.outcomes import skip
from _pytest.pathlib import bestrelpath
from _pytest.pathlib import copytree
from _pytest.pathlib import make_numbered_dir
from _pytest.reports import CollectReport
from _pytest.reports import TestReport
Expand Down Expand Up @@ -971,7 +970,7 @@ def copy_example(self, name: Optional[str] = None) -> Path:
example_path = example_dir.joinpath(name)

if example_path.is_dir() and not example_path.joinpath("__init__.py").is_file():
copytree(example_path, self.path)
shutil.copytree(example_path, self.path, symlinks=True, dirs_exist_ok=True)
return self.path
elif example_path.is_file():
result = self.path.joinpath(example_path.name)
Expand Down