inspect (11)
get_annotations¶
get_annotations(obj, *, globals=None, locals=None, eval_str=False)
Compute the annotations dict for an object.
DocStrings
Source code in python3.12/inspect.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
get_argspec¶
get_argspec(obj: Any, remove_self: bool = True) -> inspect.FullArgSpec
Return a cleaned-up FullArgSpec for given callable.
Example
Jinja call:
Result:FullArgSpec(args=['obj', 'remove_self'], varargs=None, varkw=None, defaults=(True,), kwonlyargs=[], kwonlydefaults=None, annotations={'return': 'inspect.FullArgSpec', 'obj': 'Any', 'remove_self': 'bool'})
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
A callable python object |
required |
remove_self
|
bool
|
Whether to remove "self" argument from method argspecs |
True
|
Source code in src/jinjarope/inspectfilters.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 |
|
get_deprecated_message¶
get_deprecated_message(obj: Any) -> str | None
Return deprecated message (created by deprecated decorator).
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object to check |
required |
Source code in src/jinjarope/inspectfilters.py
230 231 232 233 234 235 236 |
|
get_doc¶
get_doc(obj: Any, *, escape: bool = False, fallback: str = '', from_base_classes: bool = False, only_summary: bool = False, only_description: bool = False) -> str
Get doc for given object.
Example
Jinja call:
Result: `Get doc for given object.Args: obj: Object to get docstrings from escape: Whether docstrings should get escaped fallback: Fallback in case docstrings dont exist from_base_classes: Use base class docstrings if docstrings dont exist only_summary: Only return first line of docstrings only_description: Only return block after first line`
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object to get docstrings from |
required |
escape
|
bool
|
Whether docstrings should get escaped |
False
|
fallback
|
str
|
Fallback in case docstrings dont exist |
''
|
from_base_classes
|
bool
|
Use base class docstrings if docstrings dont exist |
False
|
only_summary
|
bool
|
Only return first line of docstrings |
False
|
only_description
|
bool
|
Only return block after first line |
False
|
Source code in src/jinjarope/inspectfilters.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
get_file¶
get_file(obj: module | type | method | function | traceback | frame | code | collections.abc.Callable[..., typing.Any]) -> pathlib.Path | None
Cached wrapper for inspect.getfile.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
HasCodeType
|
Object to get file for |
required |
Source code in src/jinjarope/inspectfilters.py
280 281 282 283 284 285 286 287 288 289 |
|
get_signature¶
get_signature(obj: collections.abc.Callable[..., typing.Any]) -> inspect.Signature
Cached wrapper for inspect.signature.
Example
Jinja call:
Result:(obj: 'Callable[..., Any]') -> 'inspect.Signature'
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Callable[..., Any]
|
Callable to get a signature for. |
required |
Source code in src/jinjarope/inspectfilters.py
259 260 261 262 263 264 265 266 |
|
get_source¶
get_source(obj: module | type | method | function | traceback | frame | code | collections.abc.Callable[..., typing.Any]) -> str
Cached wrapper for inspect.getsource.
Example
Jinja call:
Result: `@functools.cache def get_source(obj: HasCodeType) -> str: """Cached wrapper for inspect.getsource.Args:
obj: Object to return source for.
"""
return inspect.getsource(obj)
`
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
HasCodeType
|
Object to return source for. |
required |
Source code in src/jinjarope/inspectfilters.py
239 240 241 242 243 244 245 246 |
|
get_source_lines¶
get_source_lines(obj: module | type | method | function | traceback | frame | code | collections.abc.Callable[..., typing.Any]) -> tuple[list[str], int]
Cached wrapper for inspect.getsourcelines.
Example
Jinja call:
Result:(['@functools.cache\n', 'def get_source_lines(obj: HasCodeType) -> tuple[list[str], int]:\n', ' """Cached wrapper for inspect.getsourcelines.\n', '\n', ' Args:\n', ' obj: Object to return source lines for.\n', ' """\n', ' return inspect.getsourcelines(obj)\n'], 249)
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
HasCodeType
|
Object to return source lines for. |
required |
Source code in src/jinjarope/inspectfilters.py
249 250 251 252 253 254 255 256 |
|
get_structure_map¶
get_structure_map(obj: os.PathLike[str] | str, *, show_types: bool = True, show_line_numbers: bool = False, show_decorators: bool = True, sort_alphabetically: bool = False, include_private: bool = True, include_dunder: bool = False, max_depth: int | None = None, use_unicode: bool = True) -> str
Generate a textual tree representation of Python code structure.
Example
Jinja call:
Result:└── jinjarope.codetree (MODULE)
├── NodeType (CLASS)
├── Node (CLASS) [@dataclass]
├── TreeOptions (CLASS) [@dataclass]
│ └── symbols (PROPERTY) [@property]
├── _get_decorator_names (FUNCTION)
├── _should_include_node (FUNCTION)
├── parse_object (FUNCTION)
├── generate_tree (FUNCTION)
└── get_structure_map (FUNCTION)
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
PathLike[str] | str
|
Path to the Python source file or a Python object |
required |
show_types
|
bool
|
Include node type annotations |
True
|
show_line_numbers
|
bool
|
Display source line numbers |
False
|
show_decorators
|
bool
|
Include decorator information |
True
|
sort_alphabetically
|
bool
|
Sort nodes by name |
False
|
include_private
|
bool
|
Include private members |
True
|
include_dunder
|
bool
|
Include double underscore methods |
False
|
max_depth
|
int | None
|
Maximum tree depth to display |
None
|
use_unicode
|
bool
|
Use Unicode characters for tree branches |
True
|
Source code in src/jinjarope/codetree.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
list_baseclasses¶
list_baseclasses(klass: ~ClassType, *, recursive: bool = True, filter_abstract: bool = False, filter_generic: bool = True, filter_locals: bool = True) -> list[~ClassType]
Return list of all baseclasses of given klass.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
klass
|
ClassType
|
class to get subclasses from |
required |
filter_abstract
|
bool
|
whether abstract base classes should be included. |
False
|
filter_generic
|
bool
|
whether generic base classes should be included. |
True
|
filter_locals
|
bool
|
whether local base classes should be included. |
True
|
recursive
|
bool
|
whether to also get baseclasses of baseclasses. |
True
|
Source code in src/jinjarope/inspectfilters.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
list_subclasses¶
list_subclasses(klass: ~ClassType, *, recursive: bool = True, filter_abstract: bool = False, filter_generic: bool = True, filter_locals: bool = True) -> list[~ClassType]
Return list of all subclasses of given klass.
Example
Jinja call:
Result:[<class '_frozen_importlib._List'>, <class 'functools._HashedSeq'>, <class 'traceback.StackSummary'>, <class 'email.header._Accumulator'>, <class 'fsspec.core.OpenFiles'>, <class 'markdown.blockparser.State'>, <class 'smmap.util.MapRegionList'>, <class 'gitdb.fun.TopdownDeltaChunkList'>, <class 'gitdb.fun.DeltaChunkList'>, <class 'gitdb.base.IStream'>, <class 'git.remote.PushInfoList'>, <class 'git.util.IterableList'>, <class 'git.diff.DiffIndex'>, <class 'git.refs.log.RefLog'>, <class 'mknodes.info.gitrepository.CommitList'>, <class 'rich._stack.Stack'>, <class 'socketserver._Threads'>]
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
klass
|
ClassType
|
class to get subclasses from |
required |
filter_abstract
|
bool
|
whether abstract base classes should be included. |
False
|
filter_generic
|
bool
|
whether generic base classes should be included. |
True
|
filter_locals
|
bool
|
whether local base classes should be included. |
True
|
recursive
|
bool
|
whether to also get subclasses of subclasses. |
True
|
Source code in src/jinjarope/inspectfilters.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|