[pypy-commit] pypy py3.7: Merged in py3.7-pep565 (pull request #683)
rlamy
pypy.commits at gmail.com
Tue Nov 12 04:09:50 EST 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.7
Changeset: r98031:47c4c0ed3274
Date: 2019-11-12 09:08 +0000
http://bitbucket.org/pypy/pypy/changeset/47c4c0ed3274/
Log: Merged in py3.7-pep565 (pull request #683)
PEP 565: Show DeprecationWarning in __main__ by default
diff --git a/pypy/module/_warnings/interp_warnings.py b/pypy/module/_warnings/interp_warnings.py
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -4,10 +4,11 @@
from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
from pypy.interpreter.error import OperationError, oefmt
-def create_filter(space, w_category, action):
+def create_filter(space, w_category, action, modname):
+ w_modname = space.newtext(modname) if modname is not None else space.w_None
return space.newtuple([
space.newtext(action), space.w_None, w_category,
- space.w_None, space.newint(0)])
+ w_modname, space.newint(0)])
class State:
def __init__(self, space):
@@ -23,11 +24,13 @@
filters_w = []
filters_w.append(create_filter(
- space, space.w_DeprecationWarning, "ignore"))
+ space, space.w_DeprecationWarning, "default", "__main__"))
filters_w.append(create_filter(
- space, space.w_PendingDeprecationWarning, "ignore"))
+ space, space.w_DeprecationWarning, "ignore", None))
filters_w.append(create_filter(
- space, space.w_ImportWarning, "ignore"))
+ space, space.w_PendingDeprecationWarning, "ignore", None))
+ filters_w.append(create_filter(
+ space, space.w_ImportWarning, "ignore", None))
bytes_warning = space.sys.get_flag('bytes_warning')
if bytes_warning > 1:
@@ -37,12 +40,12 @@
else:
action = "default"
filters_w.append(create_filter(
- space, space.w_BytesWarning, action))
+ space, space.w_BytesWarning, action, None))
# note: in CPython, resource usage warnings are enabled by default
# in pydebug mode
filters_w.append(create_filter(
- space, space.w_ResourceWarning, "ignore"))
+ space, space.w_ResourceWarning, "ignore", None))
self.w_filters = space.newlist(filters_w)
@@ -165,8 +168,13 @@
return (w_filename, lineno, w_module, w_registry)
def check_matched(space, w_obj, w_arg):
+ # A 'None' filter always matches
if space.is_w(w_obj, space.w_None):
return True
+ # An internal plain text default filter must match exactly
+ if space.is_w(space.type(w_obj), space.w_unicode):
+ return space.eq_w(w_obj, w_arg)
+ # Otherwise assume a regex filter and call its match() method
return space.is_true(space.call_method(w_obj, "match", w_arg))
def get_filter(space, w_category, w_text, lineno, w_module):
diff --git a/pypy/module/_warnings/test/test_warnings.py b/pypy/module/_warnings/test/test_warnings.py
--- a/pypy/module/_warnings/test/test_warnings.py
+++ b/pypy/module/_warnings/test/test_warnings.py
@@ -5,7 +5,8 @@
import _warnings
assert _warnings._onceregistry == {}
assert _warnings._defaultaction == 'default'
- expected = [('ignore', None, DeprecationWarning, None, 0),
+ expected = [('default', None, DeprecationWarning, '__main__', 0),
+ ('ignore', None, DeprecationWarning, None, 0),
('ignore', None, PendingDeprecationWarning, None, 0),
('ignore', None, ImportWarning, None, 0),
('ignore', None, BytesWarning, None, 0),
More information about the pypy-commit
mailing list