-
Notifications
You must be signed in to change notification settings - Fork 36
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
Refactor affine transformations and add deprecation utils #550
Open
waltsims
wants to merge
17
commits into
master
Choose a base branch
from
refactor/deprecation-and-affine-cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ffbe871
refactor rotations and add deprecation utils
waltsims e19bcfa
update linear transformation
waltsims 20210a3
updates to pass test
waltsims 3794332
don't use deprecated functions
waltsims 8789773
update deprecated function calls
waltsims 3eceb5b
revert to rodruigez's algorirothm
waltsims eccd814
deprecate R{x,y,z}
waltsims 3132bc8
add test covrage
waltsims 146a244
furter refactoring
waltsims 5dee898
pass CI again
waltsims 4ed6185
all tests passing
waltsims 47acc1d
reorder functions to simplify PR diff
waltsims 73aa129
use numpy for cosd/sind
waltsims 56212eb
simplify further
waltsims 8557cae
Merge branch 'master' into refactor/deprecation-and-affine-cleanup
waltsims d6ea904
revert changes to compute_linear_transform
waltsims 98d6a15
Merge branch 'master' into refactor/deprecation-and-affine-cleanup
waltsims 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Utilities for handling deprecation warnings in k-Wave.""" | ||
|
||
import functools | ||
import warnings | ||
from typing import Callable, TypeVar, Any | ||
|
||
F = TypeVar("F", bound=Callable[..., Any]) | ||
|
||
|
||
def deprecated(message: str, target_version: str = "2.0.0") -> Callable[[F], F]: | ||
"""Decorator to mark functions as deprecated. | ||
|
||
Args: | ||
message: Message explaining what to use instead | ||
target_version: Version in which the function will be removed | ||
|
||
Example: | ||
@deprecated("Use new_function() instead", "2.0.0") | ||
def old_function(): | ||
pass | ||
""" | ||
|
||
def decorator(func: F) -> F: | ||
@functools.wraps(func) | ||
def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
warnings.warn( | ||
f"{func.__name__} is deprecated and will be removed in version {target_version}. {message}", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually these type of calls happen once per application lifecycle. If we display warning every time the function is called, it could be annoying. Perhaps move the warning outside of the
wrapper
but keep it still inside of thedecorator
? Since each function gets decorated only once (not sure how this will if the file is imported multiple times), a single log should be printed.