mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
bpo-44852: Support filtering over warnings without a set message (GH-27793)
Additional improvements: - messages which were compiled regular expressions aren't unpacked back into strings for unmatched warnings; - removed unnecessary "if tokens:" check (there's one before the for loop); - took `endswith` calculation out of the for loop.
This commit is contained in:
parent
3240bc62f4
commit
8cf07d3db3
1 changed files with 5 additions and 4 deletions
|
|
@ -2070,13 +2070,14 @@ def clear_ignored_deprecations(*tokens: object) -> None:
|
|||
raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
|
||||
|
||||
new_filters = []
|
||||
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
|
||||
for action, message, category, module, lineno in warnings.filters:
|
||||
if action == "ignore" and category is DeprecationWarning:
|
||||
if isinstance(message, re.Pattern):
|
||||
message = message.pattern
|
||||
if tokens:
|
||||
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
|
||||
if message.endswith(endswith):
|
||||
msg = message.pattern
|
||||
else:
|
||||
msg = message or ""
|
||||
if msg.endswith(endswith):
|
||||
continue
|
||||
new_filters.append((action, message, category, module, lineno))
|
||||
if warnings.filters != new_filters:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue