|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import warnings |
3 | 4 | from datetime import datetime |
4 | 5 | from functools import partial |
5 | 6 | from zoneinfo import ZoneInfo |
|
12 | 13 |
|
13 | 14 | from .functions import utcnow |
14 | 15 |
|
15 | | -Column: partial[RawColumn] = partial(RawColumn, nullable=False) |
16 | | -NullColumn: partial[RawColumn] = partial(RawColumn, nullable=True) |
17 | | -DateNowColumn = partial(Column, type_=DateTime(timezone=True), server_default=utcnow()) |
| 16 | + |
| 17 | +def _deprecated(name: str, replacement: str): |
| 18 | + warnings.warn( |
| 19 | + f"{name} is deprecated and will be removed in a future major release. " |
| 20 | + f"Use {replacement} instead.", |
| 21 | + DeprecationWarning, |
| 22 | + stacklevel=3, |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +_Column: partial[RawColumn] = partial(RawColumn, nullable=False) |
| 27 | + |
| 28 | + |
| 29 | +def Column(*args, **kwargs): # noqa: N802 |
| 30 | + _deprecated("Column", "Mapped[...] + mapped_column(...)") |
| 31 | + return _Column(*args, **kwargs) |
| 32 | + |
| 33 | + |
| 34 | +_NullColumn: partial[RawColumn] = partial(RawColumn, nullable=True) |
| 35 | + |
| 36 | + |
| 37 | +def NullColumn(*args, **kwargs): # noqa: N802 |
| 38 | + _deprecated("NullColumn", "Mapped[Optional[...]] + mapped_column(...)") |
| 39 | + return _NullColumn(*args, **kwargs) |
| 40 | + |
| 41 | + |
| 42 | +_DateNowColumn = partial(Column, type_=DateTime(timezone=True), server_default=utcnow()) |
| 43 | + |
| 44 | + |
| 45 | +def DateNowColumn(*args, **kwargs): # noqa: N802 |
| 46 | + _deprecated("DateNowColumn", "Mapped[datetime_now] + mapped_column(...)") |
| 47 | + return _DateNowColumn(*args, **kwargs) |
| 48 | + |
18 | 49 |
|
19 | 50 | # Module-level constants for default timezone values |
20 | 51 | _DEFAULT_UTC = ZoneInfo("UTC") |
|
32 | 63 |
|
33 | 64 |
|
34 | 65 | def EnumColumn(name, enum_type, **kwargs): # noqa: N802 |
| 66 | + _deprecated("EnumColumn", "Mapped[...] + enum_column(...)") |
35 | 67 | return Column(name, Enum(enum_type, native_enum=False, length=16), **kwargs) |
36 | 68 |
|
37 | 69 |
|
|
0 commit comments