| 242 | |
| 243 | |
| 244 | def _make_generic_wrapper(func_name, func, options_class, arity): |
| 245 | if options_class is None: |
| 246 | def wrapper(*args, memory_pool=None): |
| 247 | if arity is not Ellipsis and len(args) != arity: |
| 248 | raise TypeError( |
| 249 | f"{func_name} takes {arity} positional argument(s), " |
| 250 | f"but {len(args)} were given" |
| 251 | ) |
| 252 | if args and isinstance(args[0], Expression): |
| 253 | return Expression._call(func_name, list(args)) |
| 254 | return func.call(args, None, memory_pool) |
| 255 | else: |
| 256 | def wrapper(*args, memory_pool=None, options=None, **kwargs): |
| 257 | if arity is not Ellipsis: |
| 258 | if len(args) < arity: |
| 259 | raise TypeError( |
| 260 | f"{func_name} takes {arity} positional argument(s), " |
| 261 | f"but {len(args)} were given" |
| 262 | ) |
| 263 | option_args = args[arity:] |
| 264 | args = args[:arity] |
| 265 | else: |
| 266 | option_args = () |
| 267 | options = _handle_options(func_name, options_class, options, |
| 268 | option_args, kwargs) |
| 269 | if args and isinstance(args[0], Expression): |
| 270 | return Expression._call(func_name, list(args), options) |
| 271 | return func.call(args, options, memory_pool) |
| 272 | return wrapper |
| 273 | |
| 274 | |
| 275 | def _make_signature(arg_names, var_arg_names, options_class): |