(cls, *args: Any, **kw: Any)
| 484 | |
| 485 | @classmethod |
| 486 | def _new(cls, *args: Any, **kw: Any) -> Any: |
| 487 | if not args and not kw: |
| 488 | # python3k pickle seems to call this |
| 489 | return object.__new__(cls) |
| 490 | |
| 491 | try: |
| 492 | name, metadata, *other_args = args |
| 493 | except ValueError: |
| 494 | raise TypeError( |
| 495 | "Table() takes at least two positional-only " |
| 496 | "arguments 'name', and 'metadata'" |
| 497 | ) from None |
| 498 | if other_args and isinstance(other_args[0], type): |
| 499 | typed_columns_cls = other_args[0] |
| 500 | if not issubclass(typed_columns_cls, TypedColumns): |
| 501 | raise exc.InvalidRequestError( |
| 502 | "The ``typed_columns_cls`` argument requires a " |
| 503 | "TypedColumns subclass." |
| 504 | ) |
| 505 | elif hasattr(typed_columns_cls, "_sa_class_manager"): |
| 506 | # an orm class subclassed with TypedColumns. Reject it |
| 507 | raise exc.InvalidRequestError( |
| 508 | "To get a typed table from an ORM class, use the " |
| 509 | "`as_typed_table()` function instead." |
| 510 | ) |
| 511 | |
| 512 | extracted_columns = _extract_columns_from_class(typed_columns_cls) |
| 513 | other_args = extracted_columns + other_args[1:] |
| 514 | elif "typed_columns_cls" in kw: |
| 515 | raise TypeError( |
| 516 | "The ``typed_columns_cls`` argument may be passed " |
| 517 | "only positionally" |
| 518 | ) |
| 519 | |
| 520 | schema = kw.get("schema", None) |
| 521 | if schema is None: |
| 522 | schema = metadata.schema |
| 523 | elif schema is BLANK_SCHEMA: |
| 524 | schema = None |
| 525 | keep_existing = kw.get("keep_existing", False) |
| 526 | extend_existing = kw.get("extend_existing", False) |
| 527 | |
| 528 | if keep_existing and extend_existing: |
| 529 | msg = "keep_existing and extend_existing are mutually exclusive." |
| 530 | raise exc.ArgumentError(msg) |
| 531 | |
| 532 | must_exist = kw.pop("must_exist", kw.pop("mustexist", False)) |
| 533 | key = _get_table_key(name, schema) |
| 534 | if key in metadata.tables: |
| 535 | if not keep_existing and not extend_existing and bool(other_args): |
| 536 | raise exc.InvalidRequestError( |
| 537 | f"Table '{key}' is already defined for this MetaData " |
| 538 | "instance. Specify 'extend_existing=True' " |
| 539 | "to redefine " |
| 540 | "options and columns on an " |
| 541 | "existing Table object." |
| 542 | ) |
| 543 | table = metadata.tables[key] |
no test coverage detected