From 228655537ee3d0f6766fbfcdef5e758a12342332 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:16:29 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- CHANGELOG.md | 1 + pdoc/doc_pyi.py | 10 +- test/testdata/type_stubs.html | 140 ++++++++++++++------------- test/testdata/type_stubs/__init__.py | 4 +- 4 files changed, 82 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aae4934b..da93e31e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ To exclude modules, see https://pdoc.dev/docs/pdoc.html#exclude-submodules-from-being-documented. ([#728](https://github.com/mitmproxy/pdoc/pull/728), @mhils) - Fix a bug where pdoc would crash when importing pyi files. + ([#732](https://github.com/mitmproxy/pdoc/pull/732), @mhils) - Fix a bug where subclasses of TypedDict subclasses would not render correctly. ([#729](https://github.com/mitmproxy/pdoc/pull/729), @mhils) diff --git a/pdoc/doc_pyi.py b/pdoc/doc_pyi.py index 7e180ae7..f1df53b4 100644 --- a/pdoc/doc_pyi.py +++ b/pdoc/doc_pyi.py @@ -48,16 +48,20 @@ def find_stub_file(module_name: str) -> Path | None: def _import_stub_file(module_name: str, stub_file: Path) -> types.ModuleType: """ Import the type stub outside of the normal import machinery. - + Note that currently, for objects imported by the stub file, the _original_ module is used and not the corresponding stub file. """ sys.path_hooks.append( - importlib.machinery.FileFinder.path_hook((importlib.machinery.SourceFileLoader, ['.pyi'])) + importlib.machinery.FileFinder.path_hook( + (importlib.machinery.SourceFileLoader, [".pyi"]) + ) ) try: loader = importlib.machinery.SourceFileLoader(module_name, str(stub_file)) - spec = importlib.util.spec_from_file_location(module_name, stub_file, loader=loader) + spec = importlib.util.spec_from_file_location( + module_name, stub_file, loader=loader + ) assert spec is not None m = importlib.util.module_from_spec(spec) loader.exec_module(m) diff --git a/test/testdata/type_stubs.html b/test/testdata/type_stubs.html index 124d0547..e32a54d3 100644 --- a/test/testdata/type_stubs.html +++ b/test/testdata/type_stubs.html @@ -91,43 +91,45 @@
1""" 2This module has an accompanying .pyi file with type stubs. 3""" - 4from ._utils import ImportedClass - 5 + 4 + 5from ._utils import ImportedClass 6 - 7def func(x, y): - 8 """A simple function.""" - 9 + 7 + 8def func(x, y): + 9 """A simple function.""" 10 -11var = [] -12"""A simple variable.""" -13 +11 +12var = [] +13"""A simple variable.""" 14 -15class Class: -16 attr = 42 -17 """An attribute""" -18 -19 def meth(self, y): -20 """A simple method.""" -21 -22 class Subclass: -23 attr = "42" -24 """An attribute""" -25 -26 def meth(self, y): -27 """A simple method.""" -28 -29 def no_type_annotation(self, z): -30 """A method not present in the .pyi file.""" -31 -32 def overloaded(self, x): -33 """An overloaded method.""" -34 -35__all__ = [ -36 "func", -37 "var", -38 "Class", -39 "ImportedClass", -40] +15 +16class Class: +17 attr = 42 +18 """An attribute""" +19 +20 def meth(self, y): +21 """A simple method.""" +22 +23 class Subclass: +24 attr = "42" +25 """An attribute""" +26 +27 def meth(self, y): +28 """A simple method.""" +29 +30 def no_type_annotation(self, z): +31 """A method not present in the .pyi file.""" +32 +33 def overloaded(self, x): +34 """An overloaded method.""" +35 +36 +37__all__ = [ +38 "func", +39 "var", +40 "Class", +41 "ImportedClass", +42]
16class Class: -17 attr = 42 -18 """An attribute""" -19 -20 def meth(self, y): -21 """A simple method.""" -22 -23 class Subclass: -24 attr = "42" -25 """An attribute""" -26 -27 def meth(self, y): -28 """A simple method.""" -29 -30 def no_type_annotation(self, z): -31 """A method not present in the .pyi file.""" -32 -33 def overloaded(self, x): -34 """An overloaded method.""" +@@ -227,8 +229,8 @@17class Class: +18 attr = 42 +19 """An attribute""" +20 +21 def meth(self, y): +22 """A simple method.""" +23 +24 class Subclass: +25 attr = "42" +26 """An attribute""" +27 +28 def meth(self, y): +29 """A simple method.""" +30 +31 def no_type_annotation(self, z): +32 """A method not present in the .pyi file.""" +33 +34 def overloaded(self, x): +35 """An overloaded method."""
30 def no_type_annotation(self, z): -31 """A method not present in the .pyi file.""" + @@ -269,8 +271,8 @@
23 class Subclass: -24 attr = "42" -25 """An attribute""" -26 -27 def meth(self, y): -28 """A simple method.""" +@@ -327,8 +329,8 @@24 class Subclass: +25 attr = "42" +26 """An attribute""" +27 +28 def meth(self, y): +29 """A simple method."""
27 def meth(self, y): -28 """A simple method.""" + diff --git a/test/testdata/type_stubs/__init__.py b/test/testdata/type_stubs/__init__.py index ed00e07e..82234923 100644 --- a/test/testdata/type_stubs/__init__.py +++ b/test/testdata/type_stubs/__init__.py @@ -1,6 +1,7 @@ """ This module has an accompanying .pyi file with type stubs. """ + from ._utils import ImportedClass @@ -32,9 +33,10 @@ def no_type_annotation(self, z): def overloaded(self, x): """An overloaded method.""" + __all__ = [ "func", "var", "Class", "ImportedClass", -] \ No newline at end of file +]