-
Notifications
You must be signed in to change notification settings - Fork 145
fix: warn_deprecated now respect warnings.filter ignores #1476
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
a645c93
cf77a2d
d9bcc21
d6ec2f8
1b41152
e936d99
f67ee9a
c415bd1
0ff68b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| warn_deprecated now respected warning.filter ignores if at least "disnake" is passed to module argument. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -301,12 +301,27 @@ def warn_deprecated( | |||||||||||||||||||||||||||||||||||||||
| stacklevel = 1 # reset stacklevel, assume we just want the first frame outside library code | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| old_filters = warnings.filters[:] | ||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| warnings.simplefilter("always", DeprecationWarning) | ||||||||||||||||||||||||||||||||||||||||
| warnings.warn(*args, stacklevel=stacklevel + 1, category=DeprecationWarning, **kwargs) | ||||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||||
| assert isinstance(warnings.filters, list) | ||||||||||||||||||||||||||||||||||||||||
| warnings.filters[:] = old_filters | ||||||||||||||||||||||||||||||||||||||||
| warnings.filterwarnings(action="default", category=DeprecationWarning, module="cumbum") | ||||||||||||||||||||||||||||||||||||||||
|
hularuns marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||
| send_warning = True | ||||||||||||||||||||||||||||||||||||||||
| if len(old_filters) > 0: | ||||||||||||||||||||||||||||||||||||||||
| for action, _, category, module, _ in old_filters: | ||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||
| (category is DeprecationWarning) | ||||||||||||||||||||||||||||||||||||||||
| and ("disnake" in str(module)) | ||||||||||||||||||||||||||||||||||||||||
| and (action == "ignore") | ||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||
| send_warning = False | ||||||||||||||||||||||||||||||||||||||||
| break # break out after first disnake rule, it's good enough. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if send_warning: | ||||||||||||||||||||||||||||||||||||||||
| # this still allows force bypassing of filters if the default DeprecationWarning ignore is set. | ||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| warnings.simplefilter(action="always", category=DeprecationWarning) | ||||||||||||||||||||||||||||||||||||||||
| warnings.warn(*args, stacklevel=stacklevel + 1, category=DeprecationWarning, **kwargs) | ||||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||||
| # NOTE: Is this assertion even necessary? warnings.filters is always at minimum an empty list? | ||||||||||||||||||||||||||||||||||||||||
| assert isinstance(warnings.filters, list) | ||||||||||||||||||||||||||||||||||||||||
| warnings.filters[:] = old_filters | ||||||||||||||||||||||||||||||||||||||||
|
hularuns marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree on the guard clause instead and committed your suggestion. Just thought, after committing we could instead return within the for loop of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bool variable can be avoided by using a for ... in ...:
if condition:
break
else:
return
# here goes stuff that should run when condition is true
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the early break, i've settled for doing an early return here instead |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def oauth_url( | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.