xnano.utils.deprecation
xnano.utils.deprecation
¶
xnano.utils.deprecation
Shared deprecation helpers for APIs. Currently provides the
color -> foreground field-parameter migration used by any
dataclass or callable that pairs a foreground color with a
background.
Functions:
-
warn_color_alias–Emit the standard
colordeprecation warning. -
resolve_color_alias–Return the foreground value, honoring the deprecated
coloralias. -
resolve_renamed_alias–Return
new_value, honoring a deprecatedold_valuealias. -
warn_renamed_attribute–Decorate a renamed attribute/property getter as deprecated.
-
renamed_alias_dataclass–Add a deprecated
oldkeyword alias for a dataclassnewfield. -
renamed_alias_property–Install a deprecated alias property on a dataclass.
-
resolve_init_alias–Apply a deprecated dataclass
InitVaralias in__post_init__.
Attributes:
-
color_alias_dataclass–Deprecated
coloralias for a dataclassforegroundfield. -
align_alias_dataclass–Deprecated
alignalias for ahorizontal_alignfield.
color_alias_dataclass
module-attribute
¶
color_alias_dataclass = renamed_alias_dataclass(
"color", "foreground"
)
Deprecated color alias for a dataclass foreground field.
align_alias_dataclass
module-attribute
¶
align_alias_dataclass = renamed_alias_dataclass(
"align", "horizontal_align"
)
Deprecated align alias for a horizontal_align field.
warn_color_alias
¶
warn_color_alias(stacklevel: int = 3) -> None
Emit the standard color deprecation warning.
Parameters:
-
stacklevel(int, default:3) –Frames to skip so the warning points at caller code.
Source code in xnano/utils/deprecation.py
resolve_color_alias
¶
resolve_color_alias(
foreground: Any,
color: Any,
*,
unset: Any = None,
stacklevel: int = 3
) -> Any
Return the foreground value, honoring the deprecated color alias.
foreground wins when both are supplied. Passing color emits a
DeprecationWarning.
Parameters:
-
foreground(Any) –Canonical foreground argument.
-
color(Any) –Deprecated alias argument.
-
unset(Any, default:None) –Sentinel meaning "argument not supplied".
-
stacklevel(int, default:3) –Frames to skip so the warning points at caller code.
Returns:
-
Any–The resolved foreground value (may be
unset).
Source code in xnano/utils/deprecation.py
resolve_renamed_alias
¶
resolve_renamed_alias(
new_value: Any,
old_value: Any,
*,
old: str,
new: str,
unset: Any = None,
stacklevel: int = 3
) -> Any
Return new_value, honoring a deprecated old_value alias.
The generic form of resolve_color_alias for any renamed keyword.
The new name wins when both are supplied.
Parameters:
-
new_value(Any) –Canonical argument.
-
old_value(Any) –Deprecated alias argument.
-
old(str) –Deprecated parameter name, for the message.
-
new(str) –Replacement parameter name, for the message.
-
unset(Any, default:None) –Sentinel meaning "argument not supplied".
-
stacklevel(int, default:3) –Frames to skip so the warning points at caller code.
Returns:
-
Any–The resolved value (may be
unset).
Source code in xnano/utils/deprecation.py
warn_renamed_attribute
¶
Decorate a renamed attribute/property getter as deprecated.
Applies PEP 702 @deprecated, so type checkers render callers of the
old name with a strikethrough and a DeprecationWarning is emitted at
runtime when it is used. Apply below @property on the getter.
Parameters:
-
old(str) –Fully qualified deprecated name (e.g.
"Context.keyboard"). -
new(str) –Fully qualified replacement name.
Returns:
-
Callable[[_CallableT], _CallableT]–The
@deprecateddecorator carrying the rename message.
Source code in xnano/utils/deprecation.py
renamed_alias_dataclass
¶
Add a deprecated old keyword alias for a dataclass new field.
Wraps __init__ to accept old (deprecated, new wins when
both are given) and installs an old property mapped to new so
existing attribute reads keep working.
Parameters:
-
old(str) –Deprecated field name.
-
new(str) –Replacement field name, which the class must declare.
Returns:
-
Callable[[_ClassT], _ClassT]–A decorator augmenting the dataclass in place.
Source code in xnano/utils/deprecation.py
renamed_alias_property
¶
Install a deprecated alias property on a dataclass.
Use with a dataclass InitVar when the alias is on a hot constructor;
this keeps the generated initializer instead of wrapping it with
*args/**kwargs.
Source code in xnano/utils/deprecation.py
resolve_init_alias
¶
Apply a deprecated dataclass InitVar alias in __post_init__.