(
cls,
name: str,
docstring: str,
signature: InspectSignature,
index: int,
)
| 82 | |
| 83 | @classmethod |
| 84 | def from_inspect_signature( |
| 85 | cls, |
| 86 | name: str, |
| 87 | docstring: str, |
| 88 | signature: InspectSignature, |
| 89 | index: int, |
| 90 | ) -> Signature: |
| 91 | parameters = [] |
| 92 | |
| 93 | def get_annotation_name(annotation: object) -> str: |
| 94 | """ |
| 95 | Get annotation as string from inspect signature. |
| 96 | """ |
| 97 | try: |
| 98 | # In case the annotation is a class like "int", "float", ... |
| 99 | return str(annotation.__name__) # type: ignore |
| 100 | except AttributeError: |
| 101 | pass # No attribute `__name__`, e.g., in case of `List[int]`. |
| 102 | |
| 103 | annotation = str(annotation) |
| 104 | if annotation.startswith("typing."): |
| 105 | annotation = annotation[len("typing:") :] |
| 106 | return annotation |
| 107 | |
| 108 | for p in signature.parameters.values(): |
| 109 | parameters.append( |
| 110 | Parameter( |
| 111 | name=p.name, |
| 112 | annotation=get_annotation_name(p.annotation), |
| 113 | default=repr(p.default) |
| 114 | if p.default is not inspect.Parameter.empty |
| 115 | else None, |
| 116 | kind=p.kind, |
| 117 | ) |
| 118 | ) |
| 119 | |
| 120 | return cls( |
| 121 | name=name, |
| 122 | docstring=docstring, |
| 123 | parameters=parameters, |
| 124 | index=index, |
| 125 | returns="", |
| 126 | ) |
| 127 | |
| 128 | @classmethod |
| 129 | def from_jedi_signature(cls, signature: jedi.api.classes.Signature) -> Signature: |
no test coverage detected