| 353 | """ |
| 354 | |
| 355 | def __init__(self, func, /, *args, **keywords): |
| 356 | if not callable(func) and not hasattr(func, "__get__"): |
| 357 | raise TypeError("{!r} is not callable or a descriptor" |
| 358 | .format(func)) |
| 359 | |
| 360 | # func could be a descriptor like classmethod which isn't callable, |
| 361 | # so we can't inherit from partial (it verifies func is callable) |
| 362 | if isinstance(func, partialmethod): |
| 363 | # flattening is mandatory in order to place cls/self before all |
| 364 | # other arguments |
| 365 | # it's also more efficient since only one function will be called |
| 366 | self.func = func.func |
| 367 | self.args = func.args + args |
| 368 | self.keywords = {**func.keywords, **keywords} |
| 369 | else: |
| 370 | self.func = func |
| 371 | self.args = args |
| 372 | self.keywords = keywords |
| 373 | |
| 374 | def __repr__(self): |
| 375 | args = ", ".join(map(repr, self.args)) |