Skip to content

Commit

Permalink
fix codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed May 16, 2023
1 parent d01f42e commit f8646bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
8 changes: 6 additions & 2 deletions trio/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ async def open(self, *args, **kwargs):
__truediv__ = pathlib.Path.__truediv__
__rtruediv__ = pathlib.Path.__rtruediv__

# It might be superior to just manually implement all the methods and get rid
# of all the magic wrapping stuff.
# These should be fully typed, either manually or with some magic wrapper
# function that copies the type of pathlib.Path except sticking an async in
# front of all of them. The latter is unfortunately not trivial, see attempts in
# https://github.com/python-trio/trio/issues/2630

# wrapped methods handled by __getattr__
absolute: Any
Expand Down Expand Up @@ -274,4 +276,6 @@ async def open(self, *args, **kwargs):
# sense than inventing our own special docstring for this.
del Path.absolute.__doc__

# TODO: This is likely not supported by all the static tools out there, see discussion in
# https://github.com/python-trio/trio/pull/2631#discussion_r1185612528
os.PathLike.register(Path)
29 changes: 12 additions & 17 deletions trio/tests/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def public_modules(module):
continue
if not class_.__name__.startswith(module.__name__): # pragma: no cover
continue
if class_ is module:
if class_ is module: # pragma: no cover
continue
# We should rename the trio.tests module (#274), but until then we use
# a special-case hack:
Expand Down Expand Up @@ -102,15 +102,15 @@ def no_underscores(symbols):
completions = script.complete()
static_names = no_underscores(c.name for c in completions)
elif tool == "mypy":
if not RUN_SLOW:
if not RUN_SLOW: # pragma: no cover
pytest.skip("use --run-slow to check against mypy")
if sys.implementation.name != "cpython":
pytest.skip("mypy not installed in tests on pypy")

# create py.typed file
py_typed_path = Path(trio.__file__).parent / "py.typed"
py_typed_exists = py_typed_path.exists()
if not py_typed_exists:
if not py_typed_exists: # pragma: no cover
py_typed_path.write_text("")

# mypy behaves strangely when passed a huge semicolon-separated line with `-c`
Expand All @@ -126,7 +126,7 @@ def no_underscores(symbols):
res = run(["--config-file=", "--follow-imports=silent", str(tmpfile)])

# clean up created py.typed file
if not py_typed_exists:
if not py_typed_exists: # pragma: no cover
py_typed_path.unlink()

# check that there were no errors (exit code 0), otherwise print the errors
Expand Down Expand Up @@ -187,8 +187,6 @@ def no_hidden(symbols):
py_typed_path.write_text("")

errors: dict[str, object] = {}
if module_name == "trio.tests":
return
for class_name, class_ in module.__dict__.items():
if not isinstance(class_, type):
continue
Expand Down Expand Up @@ -249,6 +247,7 @@ def no_hidden(symbols):
missing.remove("add_note")

# TODO: why is this? Is it a problem?
# see https://github.com/python-trio/trio/pull/2631#discussion_r1185615916
if class_ == trio.StapledStream:
extra.remove("receive_stream")
extra.remove("send_stream")
Expand All @@ -257,7 +256,7 @@ def no_hidden(symbols):
if class_ == trio.Path:
missing.remove("__getattr__")

if missing or extra:
if missing or extra: # pragma: no cover
errors[f"{module_name}.{class_name}"] = {
"missing": missing,
"extra": extra,
Expand Down Expand Up @@ -298,16 +297,12 @@ def no_hidden(symbols):
f"{module_name}.{class_name}." + sorted_runtime_names[int(line) - 2]
)

# in previous iterations trio.Path.{group, owner, is_mount} needed
# to be ignored on win32 cpython. But according to codecov it was not
# needed. Noting it here in case the problem pops up again though.
# This was the accompanying comment:
# The POSIX-only attributes get listed in `dir(trio.Path)` since
# they're in `dir(pathlib.Path)` on win32 cpython. This should *maybe*
# be fixed in the future, but for now we ignore it.
if (
symbol
in ("trio.Path.group", "trio.Path.owner", "trio.Path.is_mount")
and sys.platform == "win32"
and sys.implementation.name == "cpython"
):
continue
# they're in `dir(pathlib.Path)` on win32 cpython.

# intentionally hidden from type checkers, lest they accept any attribute
if symbol == "trio.Path.__getattr__":
Expand All @@ -322,7 +317,7 @@ def no_hidden(symbols):
if "conflicts with class variable access" in message:
continue

errors[symbol] = error_type + ":" + message
errors[symbol] = error_type + ":" + message # pragma: no cover

else: # pragma: no cover
assert False, "unknown tool"
Expand Down

0 comments on commit f8646bb

Please sign in to comment.