Repository navigation
feat(common): add deprecated decorator (#300) - #472
Closed
borderlessboy wants to merge 2 commits into
Closed
borderlessboy wants to merge 2 commits into
borderlessboy wants to merge 2 commits into
Conversation
…er#300) Add pyaml.common.deprecation.deprecated, which emits a DeprecationWarning naming the deprecated function, method or class, with an optional custom message. Works on functions, methods and classes; keeps metadata via functools.wraps. Tests in tests/common/test_deprecation.py (6 passing). Full suite: 459 passed; test_tuning_orm fails on base too (Windows temp-file PermissionError).
JeanLucPons
previously approved these changes
Oct 13, 2026
GamelinAl
requested changes
Oct 15, 2026
GamelinAl
left a comment
Member
There was a problem hiding this comment.
Hi, we should probably use something based on typing_extensions.deprecated instead of starting from scratch (see https://peps.python.org/pep-0702/). For example, I think this proposal will not handle a class method which already use decorators like @classmethod or @Property.
It is to be seen but maybe just using the default python tool like @deprecated would be enough for our need.
Address review feedback (GamelinAl): replace the hand-rolled deprecated decorator with typing_extensions.deprecated. The custom wrapper returned a plain function, so composing it above @classmethod/@Property broke descriptor binding; it patched __init__ only (no __new__, no warning on subclass creation) and provided no type-checker call-site flagging. typing_extensions.deprecated handles all of these and is available on Python >= 3.11 via typing_extensions >= 4.5, now declared as a direct dependency. Tests: keep function/class/custom-message/caller-location coverage and add composition tests for @classmethod, @staticmethod and @Property in both stacking orders, matching typing_extensions' actual behavior.
Author
|
Thank you @GamelinAl for the review — agreed on all points. Reworked in b032d1c:
|
Member
|
The conclusion is that we don't need anything else than |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Reference
Closes #300
What Was Changed
pyaml/common/deprecation.py: newdeprecated(message=None)decorator. Works on functions, methods and classes. Each call or instantiation emits aDeprecationWarningnaming the object and the optional message. Usesfunctools.wraps, so name and docstring are kept.tests/common/test_deprecation.py: 6 tests (function, custom message, method, class, warning points at caller, metadata kept).Why Was It Changed
The issue asks for a standard way to mark functions and classes as deprecated, with a warning to developers. Nothing in the codebase did this before.
Screenshots
N/A (library code, no UI change).
Checklist
Additional Context
Verification (Windows, Python 3.12.14):
pytest tests/common/test_deprecation.py: 6 passed.pytest tests -m "not integration": 459 passed, 1 failed. The failure istests/tuning_tools/test_tuning_orm.py::test_tuning_orm(PermissionError on a Windows temp file). It also fails on the unmodified base commit, so it predates this change.ruff checkandruff format --checkon the two new files: clean.