[pypy-commit] pypy default: CPython compatibility (bpo-31285)

rlamy pypy.commits at gmail.com
Wed Aug 28 15:32:47 EDT 2019


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r97325:578667b3fef9
Date: 2019-08-28 20:32 +0100
http://bitbucket.org/pypy/pypy/changeset/578667b3fef9/

Log:	CPython compatibility (bpo-31285)

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
@@ -354,7 +354,7 @@
         return None
 
     # Split the source into lines.
-    w_source_list = space.call_method(w_source, "splitlines")
+    w_source_list = space.call_method(space.w_text, "splitlines", w_source)
 
     # Get the source line.
     w_source_line = space.getitem(w_source_list, space.newint(lineno - 1))
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
@@ -89,3 +89,20 @@
                              u'<str2>:831: UserWarning: \u1234\u5678\n')
         finally:
             sys.stderr = old
+
+    def test_issue31285(self):
+        import _warnings
+        def get_bad_loader(splitlines_ret_val):
+            class BadLoader:
+                def get_source(self, fullname):
+                    class BadSource(str):
+                        def splitlines(self):
+                            return splitlines_ret_val
+                    return BadSource('spam')
+            return BadLoader()
+        # does not raise:
+        _warnings.warn_explicit(
+            'eggs', UserWarning, 'bar', 1,
+            module_globals={'__loader__': get_bad_loader(42),
+                            '__name__': 'foobar'})
+


More information about the pypy-commit mailing list