(cls, *args: Any, **kw: Any)
| 431 | |
| 432 | @classmethod |
| 433 | def _new(cls, *args: Any, **kw: Any) -> Any: |
| 434 | if not args and not kw: |
| 435 | # python3k pickle seems to call this |
| 436 | return object.__new__(cls) |
| 437 | |
| 438 | try: |
| 439 | name, metadata, args = args[0], args[1], args[2:] |
| 440 | except IndexError: |
| 441 | raise TypeError( |
| 442 | "Table() takes at least two positional-only " |
| 443 | "arguments 'name' and 'metadata'" |
| 444 | ) |
| 445 | |
| 446 | schema = kw.get("schema", None) |
| 447 | if schema is None: |
| 448 | schema = metadata.schema |
| 449 | elif schema is BLANK_SCHEMA: |
| 450 | schema = None |
| 451 | keep_existing = kw.get("keep_existing", False) |
| 452 | extend_existing = kw.get("extend_existing", False) |
| 453 | |
| 454 | if keep_existing and extend_existing: |
| 455 | msg = "keep_existing and extend_existing are mutually exclusive." |
| 456 | raise exc.ArgumentError(msg) |
| 457 | |
| 458 | must_exist = kw.pop("must_exist", kw.pop("mustexist", False)) |
| 459 | key = _get_table_key(name, schema) |
| 460 | if key in metadata.tables: |
| 461 | if not keep_existing and not extend_existing and bool(args): |
| 462 | raise exc.InvalidRequestError( |
| 463 | f"Table '{key}' is already defined for this MetaData " |
| 464 | "instance. Specify 'extend_existing=True' " |
| 465 | "to redefine " |
| 466 | "options and columns on an " |
| 467 | "existing Table object." |
| 468 | ) |
| 469 | table = metadata.tables[key] |
| 470 | if extend_existing: |
| 471 | table._init_existing(*args, **kw) |
| 472 | return table |
| 473 | else: |
| 474 | if must_exist: |
| 475 | raise exc.InvalidRequestError(f"Table '{key}' not defined") |
| 476 | table = object.__new__(cls) |
| 477 | table.dispatch.before_parent_attach(table, metadata) |
| 478 | metadata._add_table(name, schema, table) |
| 479 | try: |
| 480 | table.__init__(name, metadata, *args, _no_init=False, **kw) # type: ignore[misc] # noqa: E501 |
| 481 | table.dispatch.after_parent_attach(table, metadata) |
| 482 | return table |
| 483 | except Exception: |
| 484 | with util.safe_reraise(): |
| 485 | metadata._remove_table(name, schema) |
| 486 | |
| 487 | def __init__( |
| 488 | self, |
no test coverage detected