serializer
This module defines function to serialize objects.
These functions simply take objects as parameters and return dictionaries that can be dumped by json.dumps
.
RE_FORWARD_REF = re.compile("_?ForwardRef\\('([^']+)'\\)")
module-attribute
¤
Regular expression to match forward-reference annotations of the form _ForwardRef('T')
.
RE_OPTIONAL = re.compile('Union\\[(.+), NoneType\\]')
module-attribute
¤
Regular expression to match optional annotations of the form Union[T, NoneType]
.
annotation_to_string(annotation)
¤
Return an annotation as a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation
|
Any
|
The annotation to return as a string. |
required |
Returns:
Type | Description |
---|---|
str
|
The annotation as a string. |
Source code in src/pytkdocs/serializer.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
rebuild_optional(match)
¤
Rebuild Union[T, None]
as Optional[T]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
match
|
Match
|
The match object when matching against a regular expression (by the parent caller). |
required |
Returns:
Type | Description |
---|---|
str
|
The rebuilt type string. |
Source code in src/pytkdocs/serializer.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
serialize_annotated_object(obj)
¤
Serialize an instance of AnnotatedObject
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
AnnotatedObject
|
The object to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
71 72 73 74 75 76 77 78 79 80 |
|
serialize_attribute(attribute)
¤
Serialize an instance of Attribute
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
Attribute
|
The attribute to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
serialize_docstring_section(section)
¤
Serialize an instance of inspect.Signature
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
section
|
Section
|
The section to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
serialize_object(obj)
¤
Serialize an instance of a subclass of Object
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Object
|
The object to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
serialize_parameter(parameter)
¤
Serialize an instance of Parameter
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameter
|
Parameter
|
The parameter to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
serialize_signature(signature)
¤
Serialize an instance of inspect.Signature
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signature
|
Signature
|
The signature to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
serialize_signature_parameter(parameter)
¤
Serialize an instance of inspect.Parameter
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameter
|
Parameter
|
The parameter to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
serialize_source(source)
¤
Serialize an instance of Source
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Optional[Source]
|
The source to serialize. |
required |
Returns:
Type | Description |
---|---|
dict
|
A JSON-serializable dictionary. |
Source code in src/pytkdocs/serializer.py
184 185 186 187 188 189 190 191 192 193 194 195 |
|