Initializes the unbounded functions.
()
| 424 | |
| 425 | |
| 426 | def _InitializeUnboundMethods() -> None: |
| 427 | """Initializes the unbounded functions.""" |
| 428 | # Sort the items by length, so parents get created before children. |
| 429 | items = sorted( |
| 430 | ApiFunction.unboundFunctions().items(), key=lambda x: len(x[0])) |
| 431 | |
| 432 | for name, func in items: |
| 433 | signature = func.getSignature() |
| 434 | if signature.get('hidden', False): |
| 435 | continue |
| 436 | |
| 437 | # Create nested objects as needed. |
| 438 | name_parts = name.split('.') |
| 439 | target = Algorithms |
| 440 | while len(name_parts) > 1: |
| 441 | first = name_parts[0] |
| 442 | # Set the attribute if it doesn't already exist. |
| 443 | try: |
| 444 | getattr(target, first) |
| 445 | except AttributeError: |
| 446 | setattr(target, first, _AlgorithmsContainer()) |
| 447 | |
| 448 | target = getattr(target, first) |
| 449 | name_parts = name_parts[1:] |
| 450 | |
| 451 | # Attach the function. |
| 452 | # We need a copy of the function to attach properties. |
| 453 | def GenerateFunction(f): |
| 454 | return lambda *args, **kwargs: f.call(*args, **kwargs) # pylint: disable=unnecessary-lambda |
| 455 | bound = GenerateFunction(func) |
| 456 | bound.signature = signature |
| 457 | bound.__doc__ = str(func) |
| 458 | setattr(target, name_parts[0], bound) |
| 459 | |
| 460 | |
| 461 | def _InitializeGeneratedClasses() -> None: |
no test coverage detected