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..8eb1131ee4 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, @@ -322,7 +321,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"