meshed.scrap.annotations_to_meshes
Code related to work on the “From annotated functions to meshes” discussion:
https://github.com/i2mint/meshed/discussions/55
- meshed.scrap.annotations_to_meshes.callable_annots_to_signature(callable_annots: ~collections.abc.Callable, mk_argname: ~typing.Callable[[~typing.Any, int, str], str] = <function try_annotation_name>) Signature [source]
Produces a signature from a Callable type annotation
>>> from typing import Callable, NewType >>> MyType = NewType('MyType', str) >>> sig = callable_annots_to_signature(Callable[[MyType, str], str]) >>> import inspect >>> isinstance(sig, inspect.Signature) True >>> list(sig.parameters.keys()) ['self', 'mytype', 'arg_01'] >>> sig.parameters['arg_01'].annotation <class 'str'>
- meshed.scrap.annotations_to_meshes.func_types_to_protocol(func_types: ~typing.Dict[str, ~collections.abc.Callable], name: str | None = None, *, mk_argname: ~typing.Callable[[~typing.Any, int, str], str] = <function try_annotation_name>) Protocol [source]
Produces a typing.Protocol based on a dictionary of (method_name, Callable_type) specification