diff --git a/examples/library-usage/foo.py b/examples/library-usage/foo.py index df10fcc7..f03c0971 100644 --- a/examples/library-usage/foo.py +++ b/examples/library-usage/foo.py @@ -1,6 +1,7 @@ """ Example module. We use pure Python here, but this could also be a compiled native module. """ + import enum diff --git a/pdoc/__init__.py b/pdoc/__init__.py index 5b85dc6d..914db125 100644 --- a/pdoc/__init__.py +++ b/pdoc/__init__.py @@ -462,6 +462,7 @@ def bark(self, loud: bool) -> None: It is also possible to create `pdoc.doc.Module` objects directly and modify them before rendering. You can find an example in [`examples/library-usage`](https://github.com/mitmproxy/pdoc/tree/main/examples/library-usage). ''' + from __future__ import annotations __docformat__ = "markdown" # explicitly disable rST processing in the examples above. diff --git a/pdoc/doc.py b/pdoc/doc.py index a415c841..921e88de 100644 --- a/pdoc/doc.py +++ b/pdoc/doc.py @@ -15,6 +15,7 @@ This means they have a large set of attributes that are lazily computed on first access. By convention, all attributes are read-only, although this is not enforced at runtime. """ + from __future__ import annotations from abc import ABCMeta @@ -1030,7 +1031,9 @@ class Variable(Doc[None]): kind = "variable" - default_value: Any | empty # technically Any includes empty, but this conveys intent. + default_value: ( + Any | empty + ) # technically Any includes empty, but this conveys intent. """ The variable's default value. diff --git a/pdoc/doc_ast.py b/pdoc/doc_ast.py index c04bf56b..ff86e8fa 100644 --- a/pdoc/doc_ast.py +++ b/pdoc/doc_ast.py @@ -3,6 +3,7 @@ Parsing the AST is done to extract docstrings, type annotations, and variable declarations from `__init__`. """ + from __future__ import annotations import ast @@ -51,18 +52,15 @@ def _get_source(obj: Any) -> str: @overload -def parse(obj: types.ModuleType) -> ast.Module: - ... +def parse(obj: types.ModuleType) -> ast.Module: ... @overload -def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef: - ... +def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef: ... @overload -def parse(obj: type) -> ast.ClassDef: - ... +def parse(obj: type) -> ast.ClassDef: ... def parse(obj): diff --git a/pdoc/doc_types.py b/pdoc/doc_types.py index 7b2520f6..67d2c44b 100644 --- a/pdoc/doc_types.py +++ b/pdoc/doc_types.py @@ -5,6 +5,7 @@ [typing.ForwardRef](https://docs.python.org/3/library/typing.html#typing.ForwardRef) objects without raising an exception. """ + from __future__ import annotations import functools diff --git a/pdoc/docstrings.py b/pdoc/docstrings.py index ff0fa95a..db604bb6 100644 --- a/pdoc/docstrings.py +++ b/pdoc/docstrings.py @@ -10,6 +10,7 @@ That being said, please keep the complexity low and make sure that changes are accompanied by matching snapshot tests in `test/testdata/`. """ + from __future__ import annotations import base64 diff --git a/pdoc/extract.py b/pdoc/extract.py index d79e53e2..a8ca1ca1 100644 --- a/pdoc/extract.py +++ b/pdoc/extract.py @@ -3,6 +3,7 @@ that is it loads the correct module based on whatever the user specified, and provides the rest of pdoc with some additional module metadata. """ + from __future__ import annotations from collections.abc import Iterable diff --git a/pdoc/search.py b/pdoc/search.py index f4b5bf61..63fcff7c 100644 --- a/pdoc/search.py +++ b/pdoc/search.py @@ -41,6 +41,7 @@ If you wish to disable the search functionality, you can pass `--no-search` when invoking pdoc. """ + from __future__ import annotations from collections.abc import Callable diff --git a/pdoc/web.py b/pdoc/web.py index c3512e24..9679852a 100644 --- a/pdoc/web.py +++ b/pdoc/web.py @@ -5,6 +5,7 @@ so we are content with the builtin `http.server` module. It is a bit unergonomic compared to let's say flask, but good enough for our purposes. """ + from __future__ import annotations from collections.abc import Iterable diff --git a/requirements-dev.txt b/requirements-dev.txt index 5065878f..f6182ada 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,13 +6,13 @@ # attrs==23.2.0 # via hypothesis -cachetools==5.3.2 +cachetools==5.3.3 # via tox chardet==5.2.0 # via tox colorama==0.4.6 # via tox -coverage[toml]==7.4.1 +coverage[toml]==7.4.3 # via pytest-cov distlib==0.3.8 # via virtualenv @@ -20,13 +20,13 @@ filelock==3.13.1 # via # tox # virtualenv -hypothesis==6.97.4 +hypothesis==6.98.15 # via pdoc (pyproject.toml) iniconfig==2.0.0 # via pytest jinja2==3.1.3 # via pdoc (pyproject.toml) -markupsafe==2.1.4 +markupsafe==2.1.5 # via # jinja2 # pdoc (pyproject.toml) @@ -53,7 +53,7 @@ pygments==2.17.2 # via pdoc (pyproject.toml) pyproject-api==1.6.1 # via tox -pytest==8.0.0 +pytest==8.0.2 # via # pdoc (pyproject.toml) # pytest-cov @@ -62,19 +62,19 @@ pytest-cov==4.1.0 # via pdoc (pyproject.toml) pytest-timeout==2.2.0 # via pdoc (pyproject.toml) -ruff==0.1.15 +ruff==0.3.0 # via pdoc (pyproject.toml) sortedcontainers==2.4.0 # via hypothesis -tox==4.12.1 +tox==4.13.0 # via pdoc (pyproject.toml) -types-docutils==0.20.0.20240201 +types-docutils==0.20.0.20240227 # via types-pygments types-pygments==2.17.0.20240106 # via pdoc (pyproject.toml) -types-setuptools==69.0.0.20240125 +types-setuptools==69.1.0.20240301 # via types-pygments -typing-extensions==4.9.0 +typing-extensions==4.10.0 # via mypy -virtualenv==20.25.0 +virtualenv==20.25.1 # via tox diff --git a/test/testdata/demo_long.html b/test/testdata/demo_long.html index dd015e49..6fded176 100644 --- a/test/testdata/demo_long.html +++ b/test/testdata/demo_long.html @@ -251,263 +251,264 @@
66def a_simple_function(a: str) -> str: -67 """ -68 This is a basic module-level function. -69 -70 For a more complex example, take a look at `a_complex_function`! -71 """ -72 return a.upper() +@@ -601,15 +602,15 @@67def a_simple_function(a: str) -> str: +68 """ +69 This is a basic module-level function. +70 +71 For a more complex example, take a look at `a_complex_function`! +72 """ +73 return a.upper()A Second Section
78def a_complex_function( -79 a: str, b: Union["Foo", str], *, c: Optional[T] = None -80) -> Optional[T]: -81 """ -82 This is a function with a fairly complex signature, -83 involving type annotations with `typing.Union`, a `typing.TypeVar` (~T), -84 as well as a keyword-only arguments (*). -85 """ -86 return None +@@ -631,64 +632,64 @@79def a_complex_function( +80 a: str, b: Union["Foo", str], *, c: Optional[T] = None +81) -> Optional[T]: +82 """ +83 This is a function with a fairly complex signature, +84 involving type annotations with `typing.Union`, a `typing.TypeVar` (~T), +85 as well as a keyword-only arguments (*). +86 """ +87 return NoneA Second Section
89class Foo: - 90 """ - 91 `Foo` is a basic class without any parent classes (except for the implicit `object` class). - 92 - 93 You will see in the definition of `Bar` that docstrings are inherited by default. - 94 - 95 Functions in the current scope can be referenced without prefix: `a_regular_function()`. - 96 """ - 97 - 98 an_attribute: Union[str, List["int"]] - 99 """A regular attribute with type annotations""" -100 -101 a_class_attribute: ClassVar[str] = "lots of foo!" -102 """An attribute with a ClassVar annotation.""" -103 -104 def __init__(self) -> None: -105 """ -106 The constructor is currently always listed first as this feels most natural.""" -107 self.a_constructor_only_attribute: int = 42 -108 """This attribute is defined in the constructor only, but still picked up by pdoc's AST traversal.""" -109 -110 self.undocumented_constructor_attribute = 42 -111 a_complex_function("a", "Foo") -112 -113 def a_regular_function(self) -> "Foo": -114 """This is a regular method, returning the object itself.""" -115 return self -116 -117 @property -118 def a_property(self) -> str: -119 """This is a `@property` attribute. pdoc will display it as a variable.""" -120 return "true foo" -121 -122 @cached_property -123 def a_cached_property(self) -> str: -124 """This is a `@functools.cached_property` attribute. pdoc will display it as a variable as well.""" -125 return "true foo" -126 -127 @cache -128 def a_cached_function(self) -> str: -129 """This is method with `@cache` decoration.""" -130 return "true foo" -131 -132 @classmethod -133 def a_class_method(cls) -> int: -134 """This is what a `@classmethod` looks like.""" -135 return 24 -136 -137 @classmethod # type: ignore -138 @property -139 def a_class_property(cls) -> int: -140 """This is what a `@classmethod @property` looks like.""" -141 return 24 -142 -143 @staticmethod -144 def a_static_method(): -145 """This is what a `@staticmethod` looks like.""" -146 print("Hello World") +@@ -710,14 +711,14 @@90class Foo: + 91 """ + 92 `Foo` is a basic class without any parent classes (except for the implicit `object` class). + 93 + 94 You will see in the definition of `Bar` that docstrings are inherited by default. + 95 + 96 Functions in the current scope can be referenced without prefix: `a_regular_function()`. + 97 """ + 98 + 99 an_attribute: Union[str, List["int"]] +100 """A regular attribute with type annotations""" +101 +102 a_class_attribute: ClassVar[str] = "lots of foo!" +103 """An attribute with a ClassVar annotation.""" +104 +105 def __init__(self) -> None: +106 """ +107 The constructor is currently always listed first as this feels most natural.""" +108 self.a_constructor_only_attribute: int = 42 +109 """This attribute is defined in the constructor only, but still picked up by pdoc's AST traversal.""" +110 +111 self.undocumented_constructor_attribute = 42 +112 a_complex_function("a", "Foo") +113 +114 def a_regular_function(self) -> "Foo": +115 """This is a regular method, returning the object itself.""" +116 return self +117 +118 @property +119 def a_property(self) -> str: +120 """This is a `@property` attribute. pdoc will display it as a variable.""" +121 return "true foo" +122 +123 @cached_property +124 def a_cached_property(self) -> str: +125 """This is a `@functools.cached_property` attribute. pdoc will display it as a variable as well.""" +126 return "true foo" +127 +128 @cache +129 def a_cached_function(self) -> str: +130 """This is method with `@cache` decoration.""" +131 return "true foo" +132 +133 @classmethod +134 def a_class_method(cls) -> int: +135 """This is what a `@classmethod` looks like.""" +136 return 24 +137 +138 @classmethod # type: ignore +139 @property +140 def a_class_property(cls) -> int: +141 """This is what a `@classmethod @property` looks like.""" +142 return 24 +143 +144 @staticmethod +145 def a_static_method(): +146 """This is what a `@staticmethod` looks like.""" +147 print("Hello World")A Second Section
104 def __init__(self) -> None: -105 """ -106 The constructor is currently always listed first as this feels most natural.""" -107 self.a_constructor_only_attribute: int = 42 -108 """This attribute is defined in the constructor only, but still picked up by pdoc's AST traversal.""" -109 -110 self.undocumented_constructor_attribute = 42 -111 a_complex_function("a", "Foo") +@@ -788,9 +789,9 @@105 def __init__(self) -> None: +106 """ +107 The constructor is currently always listed first as this feels most natural.""" +108 self.a_constructor_only_attribute: int = 42 +109 """This attribute is defined in the constructor only, but still picked up by pdoc's AST traversal.""" +110 +111 self.undocumented_constructor_attribute = 42 +112 a_complex_function("a", "Foo")A Second Section
113 def a_regular_function(self) -> "Foo": -114 """This is a regular method, returning the object itself.""" -115 return self +@@ -808,10 +809,10 @@114 def a_regular_function(self) -> "Foo": +115 """This is a regular method, returning the object itself.""" +116 return selfA Second Section
117 @property -118 def a_property(self) -> str: -119 """This is a `@property` attribute. pdoc will display it as a variable.""" -120 return "true foo" +@@ -829,10 +830,10 @@118 @property +119 def a_property(self) -> str: +120 """This is a `@property` attribute. pdoc will display it as a variable.""" +121 return "true foo"A Second Section
122 @cached_property -123 def a_cached_property(self) -> str: -124 """This is a `@functools.cached_property` attribute. pdoc will display it as a variable as well.""" -125 return "true foo" +@@ -853,10 +854,10 @@123 @cached_property +124 def a_cached_property(self) -> str: +125 """This is a `@functools.cached_property` attribute. pdoc will display it as a variable as well.""" +126 return "true foo"A Second Section
127 @cache -128 def a_cached_function(self) -> str: -129 """This is method with `@cache` decoration.""" -130 return "true foo" +@@ -877,10 +878,10 @@128 @cache +129 def a_cached_function(self) -> str: +130 """This is method with `@cache` decoration.""" +131 return "true foo"A Second Section
132 @classmethod -133 def a_class_method(cls) -> int: -134 """This is what a `@classmethod` looks like.""" -135 return 24 +@@ -898,11 +899,11 @@133 @classmethod +134 def a_class_method(cls) -> int: +135 """This is what a `@classmethod` looks like.""" +136 return 24A Second Section
137 @classmethod # type: ignore -138 @property -139 def a_class_property(cls) -> int: -140 """This is what a `@classmethod @property` looks like.""" -141 return 24 +@@ -923,10 +924,10 @@138 @classmethod # type: ignore +139 @property +140 def a_class_property(cls) -> int: +141 """This is what a `@classmethod @property` looks like.""" +142 return 24A Second Section
143 @staticmethod -144 def a_static_method(): -145 """This is what a `@staticmethod` looks like.""" -146 print("Hello World") +@@ -947,25 +948,25 @@144 @staticmethod +145 def a_static_method(): +146 """This is what a `@staticmethod` looks like.""" +147 print("Hello World")A Second Section
149class Bar(Foo): -150 bar: str -151 """A new attribute defined on this subclass.""" -152 -153 class Baz: -154 """ -155 This class is an attribute of `Bar`. -156 To not create overwhelmingly complex trees, pdoc flattens the class hierarchy in the documentation -157 (but not in the navigation). -158 -159 It should be noted that inner classes are a pattern you most often want to avoid in Python. -160 Think about moving stuff in a new package instead! -161 -162 This class has no __init__ method defined, so pdoc will not show a constructor. -163 """ -164 -165 def wat(self): -166 """A regular method. Above, you see what happens if a class has no constructor defined and -167 no constructor docstring.""" +@@ -1022,21 +1023,21 @@150class Bar(Foo): +151 bar: str +152 """A new attribute defined on this subclass.""" +153 +154 class Baz: +155 """ +156 This class is an attribute of `Bar`. +157 To not create overwhelmingly complex trees, pdoc flattens the class hierarchy in the documentation +158 (but not in the navigation). +159 +160 It should be noted that inner classes are a pattern you most often want to avoid in Python. +161 Think about moving stuff in a new package instead! +162 +163 This class has no __init__ method defined, so pdoc will not show a constructor. +164 """ +165 +166 def wat(self): +167 """A regular method. Above, you see what happens if a class has no constructor defined and +168 no constructor docstring."""Inherited Members
153 class Baz: -154 """ -155 This class is an attribute of `Bar`. -156 To not create overwhelmingly complex trees, pdoc flattens the class hierarchy in the documentation -157 (but not in the navigation). -158 -159 It should be noted that inner classes are a pattern you most often want to avoid in Python. -160 Think about moving stuff in a new package instead! -161 -162 This class has no __init__ method defined, so pdoc will not show a constructor. -163 """ -164 -165 def wat(self): -166 """A regular method. Above, you see what happens if a class has no constructor defined and -167 no constructor docstring.""" +@@ -1062,9 +1063,9 @@154 class Baz: +155 """ +156 This class is an attribute of `Bar`. +157 To not create overwhelmingly complex trees, pdoc flattens the class hierarchy in the documentation +158 (but not in the navigation). +159 +160 It should be noted that inner classes are a pattern you most often want to avoid in Python. +161 Think about moving stuff in a new package instead! +162 +163 This class has no __init__ method defined, so pdoc will not show a constructor. +164 """ +165 +166 def wat(self): +167 """A regular method. Above, you see what happens if a class has no constructor defined and +168 no constructor docstring."""Inherited Members
165 def wat(self): -166 """A regular method. Above, you see what happens if a class has no constructor defined and -167 no constructor docstring.""" +@@ -1086,15 +1087,15 @@166 def wat(self): +167 """A regular method. Above, you see what happens if a class has no constructor defined and +168 no constructor docstring."""Inherited Members
170async def i_am_async(self) -> int: -171 """ -172 This is an example of an async function. -173 -174 - Knock, knock -175 - An async function -176 - Who's there? -177 """ -178 raise NotImplementedError +@@ -1121,15 +1122,15 @@171async def i_am_async(self) -> int: +172 """ +173 This is an example of an async function. +174 +175 - Knock, knock +176 - An async function +177 - Who's there? +178 """ +179 raise NotImplementedErrorInherited Members
181@cache -182def fib(n): -183 """ -184 This is an example of decorated function. Decorators are included in the documentation as well. -185 This is often useful when documenting web APIs, for example. -186 """ -187 if n < 2: -188 return n -189 return fib(n - 1) + fib(n - 2) +@@ -1150,12 +1151,12 @@182@cache +183def fib(n): +184 """ +185 This is an example of decorated function. Decorators are included in the documentation as well. +186 This is often useful when documenting web APIs, for example. +187 """ +188 if n < 2: +189 return n +190 return fib(n - 1) + fib(n - 2)Inherited Members
192def security(test=os.environ): -193 """ -194 Default values are generally rendered using repr(), -195 but some special cases -- like os.environ -- are overridden to avoid leaking sensitive data. -196 """ -197 return False +@@ -1176,8 +1177,8 @@193def security(test=os.environ): +194 """ +195 Default values are generally rendered using repr(), +196 but some special cases -- like os.environ -- are overridden to avoid leaking sensitive data. +197 """ +198 return FalseInherited Members
200class DoubleInherit(Foo, Bar.Baz, abc.ABC): -201 """This is an example of a class that inherits from multiple parent classes.""" +@@ -1248,24 +1249,24 @@201class DoubleInherit(Foo, Bar.Baz, abc.ABC): +202 """This is an example of a class that inherits from multiple parent classes."""Inherited Members
210@dataclass -211class DataDemo: -212 """ -213 This is an example for a dataclass. -214 -215 As usual, you can link to individual properties: `DataDemo.a`. -216 """ -217 -218 a: int -219 """Again, we can document individual properties with docstrings.""" -220 a2: Sequence[str] -221 # This property has a type annotation but is not documented. -222 a3 = "a3" -223 # This property has a default value but is not documented. -224 a4: str = "a4" -225 # This property has a type annotation and a default value but is not documented. -226 b: bool = field(repr=False, default=True) -227 """This property is assigned to `dataclasses.field()`, which works just as well.""" +@@ -1362,10 +1363,10 @@211@dataclass +212class DataDemo: +213 """ +214 This is an example for a dataclass. +215 +216 As usual, you can link to individual properties: `DataDemo.a`. +217 """ +218 +219 a: int +220 """Again, we can document individual properties with docstrings.""" +221 a2: Sequence[str] +222 # This property has a type annotation but is not documented. +223 a3 = "a3" +224 # This property has a default value but is not documented. +225 a4: str = "a4" +226 # This property has a type annotation and a default value but is not documented. +227 b: bool = field(repr=False, default=True) +228 """This property is assigned to `dataclasses.field()`, which works just as well."""Inherited Members
230@dataclass -231class DataDemoExtended(DataDemo): -232 c: str = "42" -233 """A new attribute.""" + @@ -1422,18 +1423,18 @@Inherited Members
236class EnumDemo(enum.Enum): -237 """ -238 This is an example of an Enum. -239 -240 As usual, you can link to individual properties: `GREEN`. -241 """ -242 -243 RED = 1 -244 """I am the red.""" -245 GREEN = 2 -246 """I am green.""" -247 BLUE = enum.auto() +@@ -1505,16 +1506,16 @@237class EnumDemo(enum.Enum): +238 """ +239 This is an example of an Enum. +240 +241 As usual, you can link to individual properties: `GREEN`. +242 """ +243 +244 RED = 1 +245 """I am the red.""" +246 GREEN = 2 +247 """I am green.""" +248 BLUE = enum.auto()Inherited Members
250def embed_image(): -251 """ -252 This docstring includes an embedded image: -253 -254 ``` -255 ![pdoc logo](../docs/logo.png) -256 ``` -257 -258 ![pdoc logo](../../docs/logo.png) -259 """ +@@ -1539,25 +1540,25 @@251def embed_image(): +252 """ +253 This docstring includes an embedded image: +254 +255 ``` +256 ![pdoc logo](../docs/logo.png) +257 ``` +258 +259 ![pdoc logo](../../docs/logo.png) +260 """Inherited Members
262def admonitions(): -263 """ -264 pdoc also supports basic reStructuredText admonitions: -265 -266 ``` -267 .. note/warning/danger:: Optional title -268 Body text -269 ``` -270 -271 .. note:: -272 Hi there! -273 -274 .. warning:: Be Careful! -275 This warning has both a title and content. -276 -277 .. danger:: -278 Danger ahead. -279 -280 """ +diff --git a/test/testdata/demo_long.py b/test/testdata/demo_long.py index 742184a2..febf18c2 100644 --- a/test/testdata/demo_long.py +++ b/test/testdata/demo_long.py @@ -20,6 +20,7 @@ You can have multiple sections in your module docstring, which will also show up in the navigation. """ + from __future__ import annotations import abc diff --git a/test/testdata/demopackage.html b/test/testdata/demopackage.html index 5f10979a..0eb69abf 100644 --- a/test/testdata/demopackage.html +++ b/test/testdata/demopackage.html @@ -86,28 +86,29 @@263def admonitions(): +264 """ +265 pdoc also supports basic reStructuredText admonitions: +266 +267 ``` +268 .. note/warning/danger:: Optional title +269 Body text +270 ``` +271 +272 .. note:: +273 Hi there! +274 +275 .. warning:: Be Careful! +276 This warning has both a title and content. +277 +278 .. danger:: +279 Danger ahead. +280 +281 """
@@ -168,14 +169,14 @@1"""A test package with a sub-package at `.subpackage`.""" - 2import demopackage2 - 3 - 4from . import _child_e - 5from . import child_b - 6from ._child_d import Test - 7from .child_b import B - 8from .child_c import C - 9 -10if demopackage2: -11 pass -12 -13__all__ = [ -14 "Test", -15 "B", -16 "C", -17 "child_b", -18 "child_c", -19 "demopackage2", -20 "_child_e", -21 "child_excluded", -22 "subpackage", -23] + 2 + 3import demopackage2 + 4 + 5from . import _child_e + 6from . import child_b + 7from ._child_d import Test + 8from .child_b import B + 9from .child_c import C +10 +11if demopackage2: +12 pass +13 +14__all__ = [ +15 "Test", +16 "B", +17 "C", +18 "child_b", +19 "child_c", +20 "demopackage2", +21 "_child_e", +22 "child_excluded", +23 "subpackage", +24]
8class B: - 9 """This class is defined in .child_b. It has a B.b method.""" -10 -11 b_type: typing.Type[B] -12 """we have a self-referential attribute here""" -13 -14 def b(self): -15 return 1 +@@ -207,8 +208,8 @@9class B: +10 """This class is defined in .child_b. It has a B.b method.""" +11 +12 b_type: typing.Type[B] +13 """we have a self-referential attribute here""" +14 +15 def b(self): +16 return 1
6class C(child_b.B): - 7 """This class is defined in .child_c and inherits from .child_b.B""" - 8 - 9 def c(self): -10 return 2 +@@ -250,8 +251,8 @@7class C(child_b.B): + 8 """This class is defined in .child_c and inherits from .child_b.B""" + 9 +10 def c(self): +11 return 2
9 def c(self): -10 return 2 + diff --git a/test/testdata/demopackage/__init__.py b/test/testdata/demopackage/__init__.py index 2e90044c..872fef07 100644 --- a/test/testdata/demopackage/__init__.py +++ b/test/testdata/demopackage/__init__.py @@ -1,4 +1,5 @@ """A test package with a sub-package at `.subpackage`.""" + import demopackage2 from . import _child_e diff --git a/test/testdata/demopackage/child_b.py b/test/testdata/demopackage/child_b.py index f143e121..a4bae2b0 100644 --- a/test/testdata/demopackage/child_b.py +++ b/test/testdata/demopackage/child_b.py @@ -1,4 +1,5 @@ """child_b docstr""" + from __future__ import annotations import typing diff --git a/test/testdata/demopackage/child_c.py b/test/testdata/demopackage/child_c.py index b0ccce51..08c3b9de 100644 --- a/test/testdata/demopackage/child_c.py +++ b/test/testdata/demopackage/child_c.py @@ -1,4 +1,5 @@ """child_c docstr""" + from . import child_b diff --git a/test/testdata/demopackage2.py b/test/testdata/demopackage2.py index 9142aeeb..b781a14b 100644 --- a/test/testdata/demopackage2.py +++ b/test/testdata/demopackage2.py @@ -1,2 +1,3 @@ """I'm a different package, but I'm in demopackage.__all__!""" + x = 42 diff --git a/test/testdata/demopackage_dir.html b/test/testdata/demopackage_dir.html index c84f2229..90a2bf5c 100644 --- a/test/testdata/demopackage_dir.html +++ b/test/testdata/demopackage_dir.html @@ -336,7 +336,8 @@
@@ -637,28 +638,29 @@1"""I'm a different package, but I'm in demopackage.__all__!""" -2x = 42 +2 +3x = 42
@@ -719,14 +721,14 @@1"""A test package with a sub-package at `.subpackage`.""" - 2import demopackage2 - 3 - 4from . import _child_e - 5from . import child_b - 6from ._child_d import Test - 7from .child_b import B - 8from .child_c import C - 9 -10if demopackage2: -11 pass -12 -13__all__ = [ -14 "Test", -15 "B", -16 "C", -17 "child_b", -18 "child_c", -19 "demopackage2", -20 "_child_e", -21 "child_excluded", -22 "subpackage", -23] + 2 + 3import demopackage2 + 4 + 5from . import _child_e + 6from . import child_b + 7from ._child_d import Test + 8from .child_b import B + 9from .child_c import C +10 +11if demopackage2: +12 pass +13 +14__all__ = [ +15 "Test", +16 "B", +17 "C", +18 "child_b", +19 "child_c", +20 "demopackage2", +21 "_child_e", +22 "child_excluded", +23 "subpackage", +24]
8class B: - 9 """This class is defined in .child_b. It has a B.b method.""" -10 -11 b_type: typing.Type[B] -12 """we have a self-referential attribute here""" -13 -14 def b(self): -15 return 1 +@@ -758,8 +760,8 @@9class B: +10 """This class is defined in .child_b. It has a B.b method.""" +11 +12 b_type: typing.Type[B] +13 """we have a self-referential attribute here""" +14 +15 def b(self): +16 return 1
6class C(child_b.B): - 7 """This class is defined in .child_c and inherits from .child_b.B""" - 8 - 9 def c(self): -10 return 2 +@@ -801,8 +803,8 @@7class C(child_b.B): + 8 """This class is defined in .child_c and inherits from .child_b.B""" + 9 +10 def c(self): +11 return 2
8class B: - 9 """This class is defined in .child_b. It has a B.b method.""" -10 -11 b_type: typing.Type[B] -12 """we have a self-referential attribute here""" -13 -14 def b(self): -15 return 1 +@@ -1141,8 +1143,8 @@9class B: +10 """This class is defined in .child_b. It has a B.b method.""" +11 +12 b_type: typing.Type[B] +13 """we have a self-referential attribute here""" +14 +15 def b(self): +16 return 1
14 def b(self): -15 return 1 + @@ -1403,15 +1405,16 @@-
-1"""child_c docstr""" -2from . import child_b -3 -4 -5class C(child_b.B): -6 """This class is defined in .child_c and inherits from .child_b.B""" -7 -8 def c(self): -9 return 2 +@@ -1427,11 +1430,11 @@1"""child_c docstr""" + 2 + 3from . import child_b + 4 + 5 + 6class C(child_b.B): + 7 """This class is defined in .child_c and inherits from .child_b.B""" + 8 + 9 def c(self): +10 return 2
-6class C(child_b.B): - 7 """This class is defined in .child_c and inherits from .child_b.B""" - 8 - 9 def c(self): -10 return 2 +@@ -1450,8 +1453,8 @@7class C(child_b.B): + 8 """This class is defined in .child_c and inherits from .child_b.B""" + 9 +10 def c(self): +11 return 2
-9 def c(self): -10 return 2 + @@ -1726,19 +1729,20 @@
@@ -1754,14 +1758,14 @@1"""child_b docstr""" - 2from __future__ import annotations - 3 - 4import typing - 5 + 2 + 3from __future__ import annotations + 4 + 5import typing 6 - 7class B: - 8 """This class is defined in .child_b. It has a B.b method.""" - 9 -10 b_type: typing.Type[B] -11 """we have a self-referential attribute here""" -12 -13 def b(self): -14 return 1 + 7 + 8class B: + 9 """This class is defined in .child_b. It has a B.b method.""" +10 +11 b_type: typing.Type[B] +12 """we have a self-referential attribute here""" +13 +14 def b(self): +15 return 1
-8class B: - 9 """This class is defined in .child_b. It has a B.b method.""" -10 -11 b_type: typing.Type[B] -12 """we have a self-referential attribute here""" -13 -14 def b(self): -15 return 1 +@@ -1793,8 +1797,8 @@9class B: +10 """This class is defined in .child_b. It has a B.b method.""" +11 +12 b_type: typing.Type[B] +13 """we have a self-referential attribute here""" +14 +15 def b(self): +16 return 1
@@ -191,13 +192,13 @@14 def b(self): -15 return 1 + diff --git a/test/testdata/math_demo.html b/test/testdata/math_demo.html index f067364b..fe10a0a2 100644 --- a/test/testdata/math_demo.html +++ b/test/testdata/math_demo.html @@ -144,38 +144,39 @@Example
31 32# Example 33''' -34import math -35 +34 +35import math 36 -37def binom_coef(n: int, k: int) -> int: -38 """ -39 Return the number of ways to choose $k$ items from $n$ items without repetition and without order. -40 -41 Evaluates to $n! / (k! * (n - k)!)$ when $k <= n$ and evaluates to zero when $k > n$. -42 """ -43 return math.comb(n, k) -44 +37 +38def binom_coef(n: int, k: int) -> int: +39 """ +40 Return the number of ways to choose $k$ items from $n$ items without repetition and without order. +41 +42 Evaluates to $n! / (k! * (n - k)!)$ when $k <= n$ and evaluates to zero when $k > n$. +43 """ +44 return math.comb(n, k) 45 -46def long_formula(): -47 r""" -48 $$ -49 \Delta = -50 \Delta_\text{this} + -51 \Delta_\text{is} + -52 \Delta_\text{a} + -53 \Delta_\text{very} + -54 \Delta_\text{long} + -55 \Delta_\text{formula} + -56 \Delta_\text{that} + -57 \Delta_\text{does} + -58 \Delta_\text{not} + -59 \Delta_\text{fully} + -60 \Delta_\text{fit} + -61 \Delta_\text{on} + -62 \Delta_\text{the} + -63 \Delta_\text{screen} -64 $$ -65 """ +46 +47def long_formula(): +48 r""" +49 $$ +50 \Delta = +51 \Delta_\text{this} + +52 \Delta_\text{is} + +53 \Delta_\text{a} + +54 \Delta_\text{very} + +55 \Delta_\text{long} + +56 \Delta_\text{formula} + +57 \Delta_\text{that} + +58 \Delta_\text{does} + +59 \Delta_\text{not} + +60 \Delta_\text{fully} + +61 \Delta_\text{fit} + +62 \Delta_\text{on} + +63 \Delta_\text{the} + +64 \Delta_\text{screen} +65 $$ +66 """Example
38def binom_coef(n: int, k: int) -> int: -39 """ -40 Return the number of ways to choose $k$ items from $n$ items without repetition and without order. -41 -42 Evaluates to $n! / (k! * (n - k)!)$ when $k <= n$ and evaluates to zero when $k > n$. -43 """ -44 return math.comb(n, k) +@@ -219,26 +220,26 @@39def binom_coef(n: int, k: int) -> int: +40 """ +41 Return the number of ways to choose $k$ items from $n$ items without repetition and without order. +42 +43 Evaluates to $n! / (k! * (n - k)!)$ when $k <= n$ and evaluates to zero when $k > n$. +44 """ +45 return math.comb(n, k)Example
47def long_formula(): -48 r""" -49 $$ -50 \Delta = -51 \Delta_\text{this} + -52 \Delta_\text{is} + -53 \Delta_\text{a} + -54 \Delta_\text{very} + -55 \Delta_\text{long} + -56 \Delta_\text{formula} + -57 \Delta_\text{that} + -58 \Delta_\text{does} + -59 \Delta_\text{not} + -60 \Delta_\text{fully} + -61 \Delta_\text{fit} + -62 \Delta_\text{on} + -63 \Delta_\text{the} + -64 \Delta_\text{screen} -65 $$ -66 """ +diff --git a/test/testdata/math_demo.py b/test/testdata/math_demo.py index e985da0a..2059f5b5 100644 --- a/test/testdata/math_demo.py +++ b/test/testdata/math_demo.py @@ -31,6 +31,7 @@ def foo(): # Example ''' + import math diff --git a/test/testdata/misc_py312.html b/test/testdata/misc_py312.html index 7f2bc5ff..c6aaa9f1 100755 --- a/test/testdata/misc_py312.html +++ b/test/testdata/misc_py312.html @@ -99,54 +99,55 @@48def long_formula(): +49 r""" +50 $$ +51 \Delta = +52 \Delta_\text{this} + +53 \Delta_\text{is} + +54 \Delta_\text{a} + +55 \Delta_\text{very} + +56 \Delta_\text{long} + +57 \Delta_\text{formula} + +58 \Delta_\text{that} + +59 \Delta_\text{does} + +60 \Delta_\text{not} + +61 \Delta_\text{fully} + +62 \Delta_\text{fit} + +63 \Delta_\text{on} + +64 \Delta_\text{the} + +65 \Delta_\text{screen} +66 $$ +67 """3""" 4Testing features that either are 3.12+ only or render slightly different on 3.12. 5""" - 6from __future__ import annotations - 7 - 8import typing - 9from typing import NamedTuple -10from typing import Optional -11from typing import TypedDict -12 -13# Testing the new Python 3.12 `type` statement. -14type MyType = int -15"""A custom Python 3.12 type.""" -16 -17foo: MyType -18"""A custom type instance.""" -19 + 6 + 7from __future__ import annotations + 8 + 9import typing +10from typing import NamedTuple +11from typing import Optional +12from typing import TypedDict +13 +14# Testing the new Python 3.12 `type` statement. +15type MyType = int +16"""A custom Python 3.12 type.""" +17 +18foo: MyType +19"""A custom type instance.""" 20 -21type MyTypeWithoutDocstring = int -22 -23MyTypeClassic: typing.TypeAlias = int -24"""A "classic" typing.TypeAlias.""" -25 -26# Testing a typing.NamedTuple -27# we do not care very much about collections.namedtuple, -28# the typing version is superior for documentation and a drop-in replacement. -29 +21 +22type MyTypeWithoutDocstring = int +23 +24MyTypeClassic: typing.TypeAlias = int +25"""A "classic" typing.TypeAlias.""" +26 +27# Testing a typing.NamedTuple +28# we do not care very much about collections.namedtuple, +29# the typing version is superior for documentation and a drop-in replacement. 30 -31class NamedTupleExample(NamedTuple): -32 """ -33 An example for a typing.NamedTuple. -34 """ -35 -36 name: str -37 """Name of our example tuple.""" -38 id: int = 3 -39 +31 +32class NamedTupleExample(NamedTuple): +33 """ +34 An example for a typing.NamedTuple. +35 """ +36 +37 name: str +38 """Name of our example tuple.""" +39 id: int = 3 40 -41# Testing some edge cases in our inlined implementation of ForwardRef._evaluate in _eval_type. -42class Foo(TypedDict): -43 a: Optional[int] -44 """First attribute.""" -45 +41 +42# Testing some edge cases in our inlined implementation of ForwardRef._evaluate in _eval_type. +43class Foo(TypedDict): +44 a: Optional[int] +45 """First attribute.""" 46 -47class Bar(Foo, total=False): -48 """A TypedDict subclass. Before 3.12, TypedDict botches __mro__.""" -49 -50 b: int -51 """Second attribute.""" -52 c: str -53 # undocumented attribute +47 +48class Bar(Foo, total=False): +49 """A TypedDict subclass. Before 3.12, TypedDict botches __mro__.""" +50 +51 b: int +52 """Second attribute.""" +53 c: str +54 # undocumented attribute
32class NamedTupleExample(NamedTuple): -33 """ -34 An example for a typing.NamedTuple. -35 """ -36 -37 name: str -38 """Name of our example tuple.""" -39 id: int = 3 +@@ -292,9 +293,9 @@33class NamedTupleExample(NamedTuple): +34 """ +35 An example for a typing.NamedTuple. +36 """ +37 +38 name: str +39 """Name of our example tuple.""" +40 id: int = 3Inherited Members
43class Foo(TypedDict): -44 a: Optional[int] -45 """First attribute.""" + @@ -344,13 +345,13 @@Inherited Members
48class Bar(Foo, total=False): -49 """A TypedDict subclass. Before 3.12, TypedDict botches __mro__.""" -50 -51 b: int -52 """Second attribute.""" -53 c: str -54 # undocumented attribute +diff --git a/test/testdata/misc_py312.py b/test/testdata/misc_py312.py index f9d9f9fd..2d7db3fc 100755 --- a/test/testdata/misc_py312.py +++ b/test/testdata/misc_py312.py @@ -3,6 +3,7 @@ """ Testing features that either are 3.12+ only or render slightly different on 3.12. """ + from __future__ import annotations import typing diff --git a/test/testdata/misc_py39.html b/test/testdata/misc_py39.html index 43eda579..e6e5a2cf 100644 --- a/test/testdata/misc_py39.html +++ b/test/testdata/misc_py39.html @@ -61,36 +61,37 @@49class Bar(Foo, total=False): +50 """A TypedDict subclass. Before 3.12, TypedDict botches __mro__.""" +51 +52 b: int +53 """Second attribute.""" +54 c: str +55 # undocumented attribute
@@ -106,30 +107,30 @@1""" 2Testing features that either are 3.9+ only or render slightly different on 3.9. 3""" - 4from __future__ import annotations - 5 - 6import functools - 7from typing import Union - 8 + 4 + 5from __future__ import annotations + 6 + 7import functools + 8from typing import Union 9 -10class SingleDispatchMethodExample: -11 @functools.singledispatchmethod -12 def fancymethod(self, str_or_int: Union[str, int]): -13 """A fancy method which is capable of handling either `str` or `int`. -14 -15 :param str_or_int: string or integer to handle -16 """ -17 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") -18 -19 @fancymethod.register -20 def fancymethod_handle_str(self, str_to_handle: str): -21 """Fancy method handles a string. -22 -23 :param str_to_handle: string which will be handled -24 """ -25 print(f"{type(str_to_handle)} = '{str_to_handle}") -26 -27 @fancymethod.register -28 def _fancymethod_handle_int(self, int_to_handle: int): -29 """Fancy method handles int (not shown in doc). -30 -31 :param int_to_handle: int which will be handled -32 """ -33 print(f"{type(int_to_handle)} = '{int_to_handle:x}'") +10 +11class SingleDispatchMethodExample: +12 @functools.singledispatchmethod +13 def fancymethod(self, str_or_int: Union[str, int]): +14 """A fancy method which is capable of handling either `str` or `int`. +15 +16 :param str_or_int: string or integer to handle +17 """ +18 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") +19 +20 @fancymethod.register +21 def fancymethod_handle_str(self, str_to_handle: str): +22 """Fancy method handles a string. +23 +24 :param str_to_handle: string which will be handled +25 """ +26 print(f"{type(str_to_handle)} = '{str_to_handle}") +27 +28 @fancymethod.register +29 def _fancymethod_handle_int(self, int_to_handle: int): +30 """Fancy method handles int (not shown in doc). +31 +32 :param int_to_handle: int which will be handled +33 """ +34 print(f"{type(int_to_handle)} = '{int_to_handle:x}'")
11class SingleDispatchMethodExample: -12 @functools.singledispatchmethod -13 def fancymethod(self, str_or_int: Union[str, int]): -14 """A fancy method which is capable of handling either `str` or `int`. -15 -16 :param str_or_int: string or integer to handle -17 """ -18 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") -19 -20 @fancymethod.register -21 def fancymethod_handle_str(self, str_to_handle: str): -22 """Fancy method handles a string. -23 -24 :param str_to_handle: string which will be handled -25 """ -26 print(f"{type(str_to_handle)} = '{str_to_handle}") -27 -28 @fancymethod.register -29 def _fancymethod_handle_int(self, int_to_handle: int): -30 """Fancy method handles int (not shown in doc). -31 -32 :param int_to_handle: int which will be handled -33 """ -34 print(f"{type(int_to_handle)} = '{int_to_handle:x}'") +@@ -147,13 +148,13 @@12class SingleDispatchMethodExample: +13 @functools.singledispatchmethod +14 def fancymethod(self, str_or_int: Union[str, int]): +15 """A fancy method which is capable of handling either `str` or `int`. +16 +17 :param str_or_int: string or integer to handle +18 """ +19 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") +20 +21 @fancymethod.register +22 def fancymethod_handle_str(self, str_to_handle: str): +23 """Fancy method handles a string. +24 +25 :param str_to_handle: string which will be handled +26 """ +27 print(f"{type(str_to_handle)} = '{str_to_handle}") +28 +29 @fancymethod.register +30 def _fancymethod_handle_int(self, int_to_handle: int): +31 """Fancy method handles int (not shown in doc). +32 +33 :param int_to_handle: int which will be handled +34 """ +35 print(f"{type(int_to_handle)} = '{int_to_handle:x}'")
12 @functools.singledispatchmethod -13 def fancymethod(self, str_or_int: Union[str, int]): -14 """A fancy method which is capable of handling either `str` or `int`. -15 -16 :param str_or_int: string or integer to handle -17 """ -18 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") +@@ -180,13 +181,13 @@13 @functools.singledispatchmethod +14 def fancymethod(self, str_or_int: Union[str, int]): +15 """A fancy method which is capable of handling either `str` or `int`. +16 +17 :param str_or_int: string or integer to handle +18 """ +19 raise NotImplementedError(f"{type(str_or_int)=} not implemented!")Parameters
20 @fancymethod.register -21 def fancymethod_handle_str(self, str_to_handle: str): -22 """Fancy method handles a string. -23 -24 :param str_to_handle: string which will be handled -25 """ -26 print(f"{type(str_to_handle)} = '{str_to_handle}") +diff --git a/test/testdata/misc_py39.py b/test/testdata/misc_py39.py index c7acd514..65f60e33 100644 --- a/test/testdata/misc_py39.py +++ b/test/testdata/misc_py39.py @@ -1,6 +1,7 @@ """ Testing features that either are 3.9+ only or render slightly different on 3.9. """ + from __future__ import annotations import functools diff --git a/test/testdata/top_level_reimports.html b/test/testdata/top_level_reimports.html index a4d468c5..7b7a9e19 100644 --- a/test/testdata/top_level_reimports.html +++ b/test/testdata/top_level_reimports.html @@ -82,11 +82,12 @@21 @fancymethod.register +22 def fancymethod_handle_str(self, str_to_handle: str): +23 """Fancy method handles a string. +24 +25 :param str_to_handle: string which will be handled +26 """ +27 print(f"{type(str_to_handle)} = '{str_to_handle}")6 - `top_level_reimports._internal.baz` 7 - `top_level_reimports._internal.baz()` 8""" - 9from ._internal import Bar -10from ._internal import Foo -11from ._internal import baz -12 -13__all__ = ["Foo", "Bar", "baz"] + 9 +10from ._internal import Bar +11from ._internal import Foo +12from ._internal import baz +13 +14__all__ = ["Foo", "Bar", "baz"]
1""" 2Example where only the these children should be rendered: 3 * `__private_func_explicitly_public` and - 4 * `public_func` + 4 * `public_func` 5""" 6 7 diff --git a/test/testdata/visibility.py b/test/testdata/visibility.py index 6641dc6b..f63f2bf0 100755 --- a/test/testdata/visibility.py +++ b/test/testdata/visibility.py @@ -1,7 +1,7 @@ """ Example where only the these children should be rendered: * `__private_func_explicitly_public` and - * `public_func` + * `public_func` """