Skip to content

Commit c2a197f

Browse files
authored
Merge pull request #7839 from asottile/py36_compat_fspath
py36+: remove _pytest.compat.fspath
2 parents 5efddd3 + be43c7c commit c2a197f

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from _pytest.assertion.util import ( # noqa: F401
3434
format_explanation as _format_explanation,
3535
)
36-
from _pytest.compat import fspath
3736
from _pytest.config import Config
3837
from _pytest.main import Session
3938
from _pytest.pathlib import fnmatch_ex
@@ -306,7 +305,7 @@ def _write_pyc(
306305
pyc: Path,
307306
) -> bool:
308307
try:
309-
with atomic_write(fspath(pyc), mode="wb", overwrite=True) as fp:
308+
with atomic_write(os.fspath(pyc), mode="wb", overwrite=True) as fp:
310309
_write_pyc_fp(fp, source_stat, co)
311310
except OSError as e:
312311
state.trace("error writing pyc file at {}: {}".format(pyc, e))
@@ -336,7 +335,7 @@ def _write_pyc(
336335

337336
try:
338337
_write_pyc_fp(fp, source_stat, co)
339-
os.rename(proc_pyc, fspath(pyc))
338+
os.rename(proc_pyc, os.fspath(pyc))
340339
except OSError as e:
341340
state.trace("error writing pyc file at {}: {}".format(pyc, e))
342341
# we ignore any failure to write the cache file
@@ -350,7 +349,7 @@ def _write_pyc(
350349

351350
def _rewrite_test(fn: Path, config: Config) -> Tuple[os.stat_result, types.CodeType]:
352351
"""Read and rewrite *fn* and return the code object."""
353-
fn_ = fspath(fn)
352+
fn_ = os.fspath(fn)
354353
stat = os.stat(fn_)
355354
with open(fn_, "rb") as f:
356355
source = f.read()
@@ -368,12 +367,12 @@ def _read_pyc(
368367
Return rewritten code if successful or None if not.
369368
"""
370369
try:
371-
fp = open(fspath(pyc), "rb")
370+
fp = open(os.fspath(pyc), "rb")
372371
except OSError:
373372
return None
374373
with fp:
375374
try:
376-
stat_result = os.stat(fspath(source))
375+
stat_result = os.stat(os.fspath(source))
377376
mtime = int(stat_result.st_mtime)
378377
size = stat_result.st_size
379378
data = fp.read(12)
@@ -831,7 +830,7 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]:
831830
"assertion is always true, perhaps remove parentheses?"
832831
),
833832
category=None,
834-
filename=fspath(self.module_path),
833+
filename=os.fspath(self.module_path),
835834
lineno=assert_.lineno,
836835
)
837836

@@ -1072,7 +1071,7 @@ def try_makedirs(cache_dir: Path) -> bool:
10721071
Returns True if successful or if it already exists.
10731072
"""
10741073
try:
1075-
os.makedirs(fspath(cache_dir), exist_ok=True)
1074+
os.makedirs(os.fspath(cache_dir), exist_ok=True)
10761075
except (FileNotFoundError, NotADirectoryError, FileExistsError):
10771076
# One of the path components was not a directory:
10781077
# - we're in a zip file

src/_pytest/compat.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import enum
33
import functools
44
import inspect
5-
import os
65
import re
76
import sys
87
from contextlib import contextmanager
@@ -55,18 +54,6 @@ def _format_args(func: Callable[..., Any]) -> str:
5554
REGEX_TYPE = type(re.compile(""))
5655

5756

58-
if sys.version_info < (3, 6):
59-
60-
def fspath(p):
61-
"""os.fspath replacement, useful to point out when we should replace it by the
62-
real function once we drop py35."""
63-
return str(p)
64-
65-
66-
else:
67-
fspath = os.fspath
68-
69-
7057
def is_generator(func: object) -> bool:
7158
genfunc = inspect.isgeneratorfunction(func)
7259
return genfunc and not iscoroutinefunction(func)

0 commit comments

Comments
 (0)