-
Notifications
You must be signed in to change notification settings - Fork 20
refactor: Issue deprecation warnings for IO-functions #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,58 @@ | ||
| # Copyright (c) QuantCo 2025-2026 | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| import os | ||
| from collections.abc import Callable | ||
| from functools import wraps | ||
| from __future__ import annotations | ||
|
|
||
| TRUTHY_VALUES = ["1", "true"] | ||
| import sys | ||
| import warnings | ||
| from functools import wraps | ||
| from typing import TYPE_CHECKING, TypeVar | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
| from typing import ParamSpec | ||
|
|
||
| def skip_if(env: str) -> Callable: | ||
| """Decorator to skip warnings based on environment variable. | ||
| P = ParamSpec("P") | ||
| T = TypeVar("T") | ||
|
|
||
| If the environment variable is equivalent to any of TRUTHY_VALUES, the wrapped | ||
| function is skipped. | ||
| """ | ||
|
|
||
| def decorator(fun: Callable) -> Callable: | ||
| @wraps(fun) | ||
| def wrapper() -> None: | ||
| if os.getenv(env, "").lower() in TRUTHY_VALUES: | ||
| return | ||
| fun() | ||
| def issue_deprecation_warning(message: str, *, version: str = "") -> None: | ||
| """Issue a deprecation warning pointing at the caller of the deprecated method. | ||
|
|
||
| return wrapper | ||
| This must be called directly from the body of the deprecated (public) method so | ||
| that the warning points at the user's code rather than at dataframely internals. | ||
|
|
||
| return decorator | ||
| Args: | ||
| message: The message associated with the warning. | ||
| version: The dataframely version in which the deprecation occurred (if not | ||
| already part of ``message``). | ||
| """ | ||
| if version: | ||
| message = f"{message.strip()}\n(Deprecated in dataframely {version})" | ||
| # `stacklevel=2` blames the caller of the deprecated method (one frame up from this | ||
| # function). All call sites invoke this directly from the deprecated method body. | ||
| warnings.warn(message, DeprecationWarning, stacklevel=2) | ||
|
|
||
|
|
||
| if sys.version_info >= (3, 13): | ||
| from warnings import deprecated | ||
| else: | ||
| try: | ||
| from typing_extensions import deprecated | ||
| except ImportError: # pragma: no cover | ||
|
|
||
| def deprecated( # type: ignore[no-redef] | ||
| message: str, | ||
| ) -> Callable[[Callable[P, T]], Callable[P, T]]: | ||
| """Fallback for :func:`warnings.deprecated` without :pep:`702` support.""" | ||
|
|
||
| def decorate(function: Callable[P, T]) -> Callable[P, T]: | ||
| @wraps(function) | ||
| def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: | ||
| issue_deprecation_warning(message) | ||
| return function(*args, **kwargs) | ||
|
|
||
| wrapper.__deprecated__ = message # type: ignore[attr-defined] | ||
| return wrapper | ||
|
|
||
| return decorate |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.