Debian Codegraph @

tests/roots/test-ext-autodoc/target/pep695.py

raw
1 from __future__ import annotations
2
3 import pathlib
4 from typing import NewType, TypeAliasType
5
6 import typing_extensions
7
8 #: Some buffer-like object
9 buffer_like = bytes | bytearray | memoryview
10
11 #: Any type of path
12 pathlike = str | pathlib.Path
13
14 #: A generic type alias
15 Handler = type[Exception]
16
17
18 class Foo:
19 """This is class Foo."""
20
21
22 type Pep695Alias = Foo
23 """This is PEP695 type alias."""
24
25 type Pep695AliasUndocumented = Foo
26
27 TypeAliasTypeExplicit = TypeAliasType('TypeAliasTypeExplicit', Foo) # NoQA: UP040
28 """This is an explicitly constructed typing.TypeAlias."""
29
30 HandlerTypeAliasType = TypeAliasType('HandlerTypeAliasType', type[Exception]) # NoQA: UP040
31 """This is an explicitly constructed generic alias typing.TypeAlias."""
32
33 TypeAliasTypeExtension = typing_extensions.TypeAliasType('TypeAliasTypeExtension', Foo) # NoQA: UP040
34 """This is an explicitly constructed typing_extensions.TypeAlias."""
35
36 #: This is PEP695 complex type alias with doc comment.
37 type Pep695AliasC = dict[str, Foo]
38
39 type Pep695AliasUnion = str | int
40 """This is PEP695 type alias for union."""
41
42 type Pep695AliasOfAlias = Pep695AliasC
43 """This is PEP695 type alias of PEP695 alias."""
44
45 Bar = NewType('Bar', Pep695Alias)
46 """This is newtype of Pep695Alias."""
47
48
49 def ret_pep695(a: Pep695Alias) -> Pep695Alias:
50 """This fn accepts and returns PEP695 alias."""
51 ...
52
53
54 def read_file(path: pathlike) -> bytes:
55 """Read a file and return its contents.
56
57 Tests Union type alias cross-reference resolution.
58 """
59
60
61 def process_error(handler: Handler, other: HandlerTypeAliasType) -> str:
62 """Process an error with a custom handler type.
63
64 Tests generic type alias cross-reference resolution.
65 """
66
67
68 def buffer_len(data: buffer_like) -> int:
69 """Return length of a buffer-like object.
70
71 Tests Union type alias cross-reference resolution.
72 """