inspect (12)
get_annotations¶
get_annotations(obj, *, globals=None, locals=None, eval_str=False)
Compute the annotations dict for an object.
DocStrings
Source code in python3.13/inspect.py
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 295 296 | |
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
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 |
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, or import path string (supports both "module.path:object" and "module.path.object") 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, or import path string (supports both "module.path:object" and "module.path.object") |
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
get_file¶
get_file(obj: module | type | method | function | traceback | frame | code | collections.abc.Callable[..., typing.Any]) -> pathlib._local.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
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 |
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 |
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'], 284)
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
HasCodeType
|
Object to return source lines for. |
required |
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
iter_union_types¶
iter_union_types(union_type: Any, *, filter_none: bool = True) -> collections.abc.Iterator[type]
Iterate through all types in a Union.
Example
Jinja call:
{%- set typing = "typing" | import_module -%}
{%- for typ in typing.Union[str, int, None] | iter_union_types -%}
{{ typ }}
{% endfor -%}
<class 'str'>
<class 'int'>
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
union_type
|
Any
|
A Union type (e.g., Union[A, B, C] or A | B | C) |
required |
filter_none
|
bool
|
Whether to filter out NoneType from the results |
True
|
Yields:
| Type | Description |
|---|---|
type
|
Each type found in the union |
Source code in src/jinjarope/inspectfilters.py
list_baseclasses¶
list_baseclasses(klass: type, *, recursive: bool = True, filter_abstract: bool = False, filter_generic: bool = True, filter_locals: bool = True) -> list[type]
Return list of all baseclasses of given klass.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
klass
|
type
|
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
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 'githarbor.core.datatypes.NiceReprList'>, <class 'git_changelog._internal.commit._Trailers'>, <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 'unittest.mock._CallList'>, <class 'unittest.mock._AnyComparer'>, <class 'pydantic_ai._enqueue.PendingMessageQueue'>, <class 'pydantic_ai._enqueue.EnqueueGuard'>, <class 'pydantic_ai._run_context.EventStreamBuffer'>, <class 'pydantic_ai._run_context.RealtimeEventBuffer'>, <class 'pydantic_ai._history_mirroring.HistoryMirroringMessages'>, <class 'agentpool.messaging.messages.TeamResponse'>, <class 'agentpool.delegation.teamrun.ExtendedTeamTalk'>, <class 'agentpool.talk.talk.TeamTalk'>, <class 'socketserver._Threads'>, <class 'logging.config.ConvertingList'>, <class 'anthropic._models._EagerIterable'>]
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
|