-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
extra_stacklevel
argument to better control deprecated fun…
…ction call references (#69) * Add extra_stacklevel argument * Add functional test * Update CHANGELOG * Improve documentation * Refactor: Move function wrapping logic into adapter * Add suggested tutorial updates Co-authored-by: Laurent LAPORTE <[email protected]> * Add suggested unit test for extra_stacklevel Co-authored-by: Laurent LAPORTE <[email protected]> * docs: fix typo and grammar in docstrings and comments * fix(typing): improve parameter typing --------- Co-authored-by: Laurent LAPORTE <[email protected]>
- Loading branch information
Showing
6 changed files
with
193 additions
and
50 deletions.
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
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
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
24 changes: 24 additions & 0 deletions
24
docs/source/tutorial/warning_ctrl/extra_stacklevel_demo.py
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,24 @@ | ||
import warnings | ||
|
||
from deprecated import deprecated | ||
|
||
|
||
@deprecated(version='1.0', extra_stacklevel=1) | ||
class MyObject(object): | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
def __str__(self): | ||
return "object: {name}".format(name=self.name) | ||
|
||
|
||
def create_object(name): | ||
return MyObject(name) | ||
|
||
|
||
if __name__ == '__main__': | ||
warnings.filterwarnings("default", category=DeprecationWarning) | ||
# warn here: | ||
print(create_object("orange")) | ||
# and also here: | ||
print(create_object("banane")) |
Oops, something went wrong.