Create a parameter object from an inspect.Parameter.
(self, param: inspect.Parameter)
| 161 | return mapping |
| 162 | |
| 163 | def _make_parameter(self, param: inspect.Parameter) -> Parameter: |
| 164 | """Create a parameter object from an inspect.Parameter.""" |
| 165 | try: |
| 166 | # Use type_hints instead of param.annotation to get |
| 167 | # resolved forward references and stripped Annotated. |
| 168 | annotation = self.type_hints[param.name] |
| 169 | except KeyError: |
| 170 | logger.warning("Missing type annotation for parameter '%s'", param.name) |
| 171 | annotation = Any |
| 172 | |
| 173 | if isinstance(annotation, dataclasses.InitVar): |
| 174 | annotation: Any = annotation.type |
| 175 | |
| 176 | # Get the annotated type (with Annotated preserved) for metadata extraction. |
| 177 | # This is needed when `from __future__ import annotations` is used, |
| 178 | # which causes param.annotation to be a string instead of a type. |
| 179 | try: |
| 180 | annotated_type = self.type_hints_with_extras[param.name] |
| 181 | except KeyError: |
| 182 | annotated_type = param.annotation |
| 183 | |
| 184 | return Parameter( |
| 185 | name=get_alt_name(annotated_type) or normalize_name(param.name), |
| 186 | signature=param, |
| 187 | resolved_type=annotation, |
| 188 | is_nullable=is_nullable(TypeHint(annotation)), |
| 189 | doc=get_doc(annotated_type), |
| 190 | ignore=get_ignore(annotated_type), |
| 191 | default_path=get_default_path(annotated_type), |
| 192 | default_address=get_default_address(annotated_type), |
| 193 | deprecated=get_deprecated(annotated_type), |
| 194 | conv=self.converter, |
| 195 | ) |
| 196 | |
| 197 | @property |
| 198 | def return_type(self) -> Any: |
no test coverage detected