diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-31 05:01:00 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-31 05:01:00 (GMT) |
commit | d6bfa94493b897f45ab939208a4a54a259a530e8 (patch) | |
tree | acb88e88abfbb21a554dc7205cf2e339a85d5d7c | |
parent | 59ea508bb84006b8e93ff036aa8d9f0a3fa232c7 (diff) | |
download | cpython-d6bfa94493b897f45ab939208a4a54a259a530e8.zip cpython-d6bfa94493b897f45ab939208a4a54a259a530e8.tar.gz cpython-d6bfa94493b897f45ab939208a4a54a259a530e8.tar.bz2 |
Issue #21853: Fixed the inspect module in unicode disabled build.
-rw-r--r-- | Lib/inspect.py | 9 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 9336943..b08e145 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -969,8 +969,13 @@ def getcallargs(func, *positional, **named): assign(varkw, named) elif named: unexpected = next(iter(named)) - if isinstance(unexpected, unicode): - unexpected = unexpected.encode(sys.getdefaultencoding(), 'replace') + try: + unicode + except NameError: + pass + else: + if isinstance(unexpected, unicode): + unexpected = unexpected.encode(sys.getdefaultencoding(), 'replace') raise TypeError("%s() got an unexpected keyword argument '%s'" % (f_name, unexpected)) unassigned = num_args - len([arg for arg in args if is_assigned(arg)]) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 4130cd0..ecc04cb 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -8,7 +8,7 @@ import datetime from UserList import UserList from UserDict import UserDict -from test.test_support import run_unittest, check_py3k_warnings +from test.test_support import run_unittest, check_py3k_warnings, have_unicode with check_py3k_warnings( ("tuple parameter unpacking has been removed", SyntaxWarning), @@ -17,7 +17,10 @@ with check_py3k_warnings( from test import inspect_fodder2 as mod2 # C module for test_findsource_binary -import unicodedata +try: + import unicodedata +except ImportError: + unicodedata = None # Functions tested in this suite: # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, @@ -798,7 +801,8 @@ class TestGetcallargsFunctions(unittest.TestCase): self.assertEqualException(f, '2, c=3') self.assertEqualException(f, '2, 3, c=4') self.assertEqualException(f, '2, c=4, b=3') - self.assertEqualException(f, '**{u"\u03c0\u03b9": 4}') + if have_unicode: + self.assertEqualException(f, '**{u"\u03c0\u03b9": 4}') # f got multiple values for keyword argument self.assertEqualException(f, '1, a=2') self.assertEqualException(f, '1, **{"a":2}') |