Identifies mandatory parameters (those without default values) for a function. Returns: A list of strings, where each string is the name of a mandatory parameter.
(
self,
)
| 326 | yield item |
| 327 | |
| 328 | def _get_mandatory_args( |
| 329 | self, |
| 330 | ) -> list[str]: |
| 331 | """Identifies mandatory parameters (those without default values) for a function. |
| 332 | |
| 333 | Returns: |
| 334 | A list of strings, where each string is the name of a mandatory parameter. |
| 335 | """ |
| 336 | signature = inspect.signature(self.func) |
| 337 | mandatory_params = [] |
| 338 | |
| 339 | for name, param in signature.parameters.items(): |
| 340 | # A parameter is mandatory if: |
| 341 | # 1. It has no default value (param.default is inspect.Parameter.empty) |
| 342 | # 2. It's not a variable positional (*args) or variable keyword (**kwargs) parameter |
| 343 | # |
| 344 | # For more refer to: https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind |
| 345 | if param.default == inspect.Parameter.empty and param.kind not in ( |
| 346 | inspect.Parameter.VAR_POSITIONAL, |
| 347 | inspect.Parameter.VAR_KEYWORD, |
| 348 | ): |
| 349 | mandatory_params.append(name) |
| 350 | |
| 351 | return mandatory_params |