| 222 | |
| 223 | |
| 224 | def _handle_options(name, options_class, options, args, kwargs): |
| 225 | if args or kwargs: |
| 226 | if options is not None: |
| 227 | raise TypeError( |
| 228 | f"Function {name!r} called with both an 'options' argument " |
| 229 | f"and additional arguments") |
| 230 | return options_class(*args, **kwargs) |
| 231 | |
| 232 | if options is not None: |
| 233 | if isinstance(options, dict): |
| 234 | return options_class(**options) |
| 235 | elif isinstance(options, options_class): |
| 236 | return options |
| 237 | raise TypeError( |
| 238 | f"Function {name!r} expected a {options_class} parameter, " |
| 239 | f"got {type(options)}") |
| 240 | |
| 241 | return None |
| 242 | |
| 243 | |
| 244 | def _make_generic_wrapper(func_name, func, options_class, arity): |