[pypy-commit] pypy fix_module_repr: Respond to mjacob's feedback.
marky1991
pypy.commits at gmail.com
Wed Feb 24 04:07:02 EST 2016
Author: Mark Young <marky1991 at gmail.com>
Branch: fix_module_repr
Changeset: r82476:97351ee2ac6f
Date: 2016-02-22 22:27 -0500
http://bitbucket.org/pypy/pypy/changeset/97351ee2ac6f/
Log: Respond to mjacob's feedback.
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -138,7 +138,7 @@
w___file__ = space.getattr(self, space.wrap('__file__'))
except OperationError:
w___file__ = space.w_None
- if not space.is_true(space.isinstance(w___file__, space.w_unicode)):
+ if not space.isinstance_w(w___file__, space.w_unicode):
if w_loader is not None:
w_loader_repr = space.unicode_w(space.repr(w_loader))
return space.wrap(u"<module %s (%s)>" % (name, w_loader_repr))
diff --git a/pypy/interpreter/test/test_module.py b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -80,15 +80,13 @@
assert repr(m).startswith("<module '?'")
def test_repr_with_loader_with_valid_module_repr(self):
- import _frozen_importlib, sys
+ import sys
test_module = type(sys)("test_module", "doc")
# If the module has a __loader__ and that loader has a module_repr()
# method, call it with a single argument, which is the module object.
# The value returned is used as the module’s repr.
- class CustomLoader(_frozen_importlib.BuiltinImporter):
- """Operates just like the builtin importer, but returns its own
- special repr."""
+ class CustomLoader:
@classmethod
def module_repr(cls, module):
mod_repr = ("<module {mod_name}: "
@@ -99,33 +97,25 @@
assert repr(test_module) == "<module 'test_module': 'CustomLoader' Test>"
def test_repr_with_loader_with_module_repr_wrong_type(self):
- import _frozen_importlib, sys
+ import sys
test_module = type(sys)("test_module", "doc")
# This return value must be a string.
- class BuggyCustomLoader(_frozen_importlib.BuiltinImporter):
- """Operates just like the builtin importer, but implements a
- module_repr method that returns a non-string value."""
+ class BuggyCustomLoader:
@classmethod
def module_repr(cls, module):
return 5
test_module.__loader__ = BuggyCustomLoader
- try:
- repr(test_module)
- assert False, "module_repr must fail if it returns a nonstring."
- except TypeError:
- pass
+ raises(TypeError, repr, test_module)
def test_repr_with_loader_with_raising_module_repr(self):
- import _frozen_importlib, sys
+ import sys
test_module = type(sys)("test_module", "doc")
# If an exception occurs in module_repr(), the exception is caught
# and discarded, and the calculation of the module’s repr continues
# as if module_repr() did not exist.
- class CustomLoaderWithRaisingRepr(_frozen_importlib.BuiltinImporter):
- """Operates just like the builtin importer, but implements a
- module_repr method that raises an exception."""
+ class CustomLoaderWithRaisingRepr:
@classmethod
def module_repr(cls, module):
return repr(1/0)
@@ -140,10 +130,10 @@
assert mod_repr == expected_repr
def test_repr_with_raising_loader_and___file__(self):
- import _frozen_importlib, sys
+ import sys
test_module = type(sys)("test_module", "doc")
test_module.__file__ = "/fake_dir/test_module.py"
- class CustomLoaderWithRaisingRepr(_frozen_importlib.BuiltinImporter):
+ class CustomLoaderWithRaisingRepr:
"""Operates just like the builtin importer, but implements a
module_repr method that raises an exception."""
@classmethod
@@ -160,13 +150,12 @@
assert repr(test_module) == expected_repr
def test_repr_with_missing_name(self):
- import _frozen_importlib, sys
+ import sys
test_module = type(sys)("test_module", "doc")
del test_module.__name__
mod_repr = repr(test_module)
assert mod_repr == "<module '?'>"
-
def test_dir(self):
import sys
items = sys.__dir__()
More information about the pypy-commit
mailing list