From f8646bb629000e2aebe2777ba3938ccd51184514 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 16 May 2023 13:00:10 +0200 Subject: [PATCH] fix codecov --- trio/_path.py | 8 ++++++-- trio/tests/test_exports.py | 29 ++++++++++++----------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/trio/_path.py b/trio/_path.py index 18405c59ce..7c338dbc97 100644 --- a/trio/_path.py +++ b/trio/_path.py @@ -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 @@ -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) diff --git a/trio/tests/test_exports.py b/trio/tests/test_exports.py index 74700220c4..6e5d3dd728 100644 --- a/trio/tests/test_exports.py +++ b/trio/tests/test_exports.py @@ -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: @@ -102,7 +102,7 @@ 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") @@ -110,7 +110,7 @@ def no_underscores(symbols): # 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` @@ -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 @@ -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 @@ -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") @@ -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, @@ -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__": @@ -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"