You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Lib/test/regrtest.py", line 1197, in <module>
main()
File "Lib/test/regrtest.py", line 411, in main
testdir, huntrleaks)
File "Lib/test/regrtest.py", line 570, in runtest
testdir, huntrleaks)
File "Lib/test/regrtest.py", line 623, in runtest_innerprint("test", test, "failed --", msg)
File "/temp/python/py3k/Lib/io.py", line 1459, in write
b = encoder.encode(s)
File "/temp/python/py3k/Lib/encodings/ascii.py", line 22, in encodereturn codecs.ascii_encode(input, self.errors)[0]
UnicodeEncodeError: 'ascii' codec can't encode characters in position697-699: ordinal not in range(128)
Bingo! doctest sets the __builtins__._ variable,
and the last doctest in decimal.py (in lexicographic order) is
Decimal.__round__, which ends with
>>> round(Decimal('sNaN123'), 0)
Decimal('NaN123')
This is the value you see in Benjamin's output.
+ __builtins__._ = None
+
# Try to clean up junk commonly left behind. While tests shouldn't
leave
# any files or directories behind, when a test fails that can be
tedious
# for it to arrange. The consequences can be especially nasty on
Windows,
On Tue, Jul 29, 2008 at 8:30 AM, Amaury Forgeot d'Arc
<report@bugs.python.org> wrote:
>
> Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:
>
> Bingo! doctest sets the __builtins__._ variable,
> and the last doctest in decimal.py (in lexicographic order) is
> Decimal.__round__, which ends with
> >>> round(Decimal('sNaN123'), 0)
> Decimal('NaN123')
> This is the value you see in Benjamin's output.
>
> Here is a trivial patch:
Shouldn't this be fixed in test_decimal so it cleans properly after it's self?
I was leaning towards the "doctest should not pollute the __builtins__
module" side.
test_decimal might not be the only test that leaks one object outside
the module.
« But why is __builtins__ a module in __main__ and a dict elsewhere?
Because in *interactive* mode, printing vars() would include
__builtins__, which would be rather large. Code that incorrectly
assumes it's always one or the other is incorrect and has always been
incorrect; the wart was present when this feature first appeared.
Since this has never been documented AFAIK, it's probably just been
(incorrectly) reverse-engineered and copied around. »
Activity
benjaminp commentedon Jul 29, 2008
In Py3k:
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'NameError': <class 'NameError'>, 'BytesWarning':
<class 'BytesWarning'>, 'dict': <class 'dict'>, 'IOError': <class
'IOError'>, 'oct': , 'bin': , 'SystemExit': <class 'SystemExit'>, 'format': , 'repr': , 'sorted': , 'False': False, 'RuntimeWarning': <class 'RuntimeWarning'>,
'list': <class 'list'>, 'iter': , 'Warning':
<class 'Warning'>, 'package': None, 'round': , 'dir': , 'cmp': ,
'set': <class 'set'>, 'bytes': <class 'bytes'>, 'UnicodeTranslateError':
<class 'UnicodeTranslateError'>, 'issubclass': , 'EOFError': <class 'EOFError'>, 'locals': , 'BufferError': <class 'BufferError'>, 'slice': <class
'slice'>, 'FloatingPointError': <class 'FloatingPointError'>, 'sum':
, 'getattr': , 'abs':
, 'exit': Use exit() or Ctrl-D (i.e. EOF) to
exit, 'print': , 'True': True, 'FutureWarning':
<class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>,
'None': None, 'hash': , 'ReferenceError': <class
'ReferenceError'>, 'len': , 'credits': Thanks
to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more
information., 'frozenset': <class 'frozenset'>, 'name': 'builtins',
'ord': , 'super': <class 'super'>, '_':
Decimal('NaN123'), 'TypeError': <class 'TypeError'>, 'license': Type
license() to see the full license text, 'KeyboardInterrupt': <class
'KeyboardInterrupt'>, 'UserWarning': <class 'UserWarning'>, 'filter':
<class 'filter'>, 'range': <class 'range'>, 'staticmethod': <class
'staticmethod'>, 'SystemError': <class 'SystemError'>, 'BaseException':
<class 'BaseException'>, 'pow': , 'RuntimeError':
<class 'RuntimeError'>, 'float': <class 'float'>, 'MemoryError': <class
'MemoryError'>, 'StopIteration': <class 'StopIteration'>, 'globals':
, 'divmod': ,
'enumerate': <class 'enumerate'>, 'Ellipsis': Ellipsis, 'LookupError':
<class 'LookupError'>, 'open': <class 'io.OpenWrapper'>, 'quit': Use
quit() or Ctrl-D (i.e. EOF) to exit, 'UnicodeError': <class
'UnicodeError'>, 'zip': <class 'zip'>, 'hex': ,
'next': , 'ImportError': <class 'ImportError'>,
'chr': , 'type': <class 'type'>, 'doc':
"Built-in functions, exceptions, and other objects.\n\nNoteworthy: None
is the
nil' object; Ellipsis represents...' in slices.", 'Exception':<class 'Exception'>, 'tuple': <class 'tuple'>, 'reversed': <class
'reversed'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>,
'input': , 'hasattr': , 'delattr': , 'setattr': , 'SyntaxWarning': <class 'SyntaxWarning'>, 'compile':
, 'ArithmeticError': <class
'ArithmeticError'>, 'str': <class 'str'>, 'property': <class
'property'>, 'GeneratorExit': <class 'GeneratorExit'>, 'int': <class
'int'>, 'import': , 'KeyError': <class
'KeyError'>, 'PendingDeprecationWarning': <class
'PendingDeprecationWarning'>, 'EnvironmentError': <class
'EnvironmentError'>, 'ascii': , 'id': , 'OSError': <class 'OSError'>, 'DeprecationWarning': <class
'DeprecationWarning'>, 'min': , 'UnicodeWarning':
<class 'UnicodeWarning'>, 'any': , 'complex':
<class 'complex'>, 'bool': <class 'bool'>, 'ValueError': <class
'ValueError'>, 'NotImplemented': NotImplemented, 'map': <class 'map'>,
'exec': , 'max': ,
'object': <class 'object'>, 'TabError': <class 'TabError'>,
'ZeroDivisionError': <class 'ZeroDivisionError'>, 'eval': , 'debug': True, 'IndentationError': <class
'IndentationError'>, 'AssertionError': <class 'AssertionError'>,
'classmethod': <class 'classmethod'>, 'UnboundLocalError': <class
'UnboundLocalError'>, 'NotImplementedError': <class
'NotImplementedError'>, 'AttributeError': <class 'AttributeError'>,
'OverflowError': <class 'OverflowError'>}, 'file':
'/temp/python/py3k/Lib/test/test_builtin.py', 'BuiltinTest': <class
'test.test_builtin.BuiltinTest'>, 'TestFailingBool': <class
'test.test_builtin.TestFailingBool'>, 'sys': <module 'sys' (built-in)>,
'test': <module 'test' from '/temp/python/py3k/Lib/test/init.py'>,
'name': 'test.test_builtin', 'unlink': <function unlink at
0x7a5540>, 'TESTFN': '@test', 'TestSorted': <class
'test.test_builtin.TestSorted'>, 'BitBucket': <class
'test.test_builtin.BitBucket'>, 'fcmp': <function fcmp at 0x7ad540>} !=
{'unittest': <module 'unittest' from
'/temp/python/py3k/Lib/unittest.py'>, 'random': <module 'random' from
'/temp/python/py3k/Lib/random.py'>, 'test_conv_no_sign': [('0', 0),
('1', 1), ('9', 9), ('10', 10), ('99', 99), ('100', 100), ('314', 314),
(' 314', 314), ('314 ', 314), (' \t\t 314 \t\t ', 314),
('2147483647', 2147483647), (' 1x', <class 'ValueError'>), (' 1 ',
1), (' 1\x02 ', <class 'ValueError'>), ('', <class 'ValueError'>), ('
', <class 'ValueError'>), (' \t\t ', <class 'ValueError'>),
('\u0663\u0661\u0664 ', 314), ('\u0200', <class 'ValueError'>)],
'test_conv_sign': [('0', 0), ('1', 1), ('9', 9), ('10', 10), ('99', 99),
('100', 100), ('314', 314), (' 314', <class 'ValueError'>), ('314 ',
314), (' \t\t 314 \t\t ', <class 'ValueError'>), ('2147483647',
2147483647), (' 1x', <class 'ValueError'>), (' 1 ', <class
'ValueError'>), (' 1\x02 ', <class 'ValueError'>), ('', <class
'ValueError'>), (' ', <class 'ValueError'>), (' \t\t ', <class
'ValueError'>), ('\u0663\u0661\u0664 ', 314), ('\u0200', <class
'ValueError'>)], 'run_with_locale': <function run_with_locale at
0x10b0390>, 'io': <module 'io' from '/temp/python/py3k/Lib/io.py'>,
'Squares': <class 'test.test_builtin.Squares'>, 'neg': , 'package': None, 'collections': <module 'collections'
from '/temp/python/py3k/Lib/collections.py'>, 'TestFailingIter': <class
'test.test_builtin.TestFailingIter'>, 'run_unittest': <function
run_unittest at 0x10b0540>, 'doc': None, 'test_main': <function
test_main at 0x1474390>, 'fractions': <module 'fractions' from
'/temp/python/py3k/Lib/fractions.py'>, 'StrSquares': <class
'test.test_builtin.StrSquares'>, 'warnings': <module 'warnings' from
'/temp/python/py3k/Lib/warnings.py'>, 'builtins': {'bytearray':
<class 'bytearray'>, 'IndexError': <class 'IndexError'>, 'all':
, 'help': Type help() for interactive help, or
help(object) for help about object., 'vars': ,
'SyntaxError': <class 'SyntaxError'>, 'UnicodeDecodeError': <class
'UnicodeDecodeError'>, 'memoryview': <class 'memoryview'>, 'isinstance':
, 'build_class': , 'copyright': Copyright (c) 2001-2008 Python Software
Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'NameError': <class 'NameError'>, 'BytesWarning':
<class 'BytesWarning'>, 'dict': <class 'dict'>, 'IOError': <class
'IOError'>, 'oct': , 'bin': , 'SystemExit': <class 'SystemExit'>, 'format': , 'repr': , 'sorted': , 'False': False, 'RuntimeWarning': <class 'RuntimeWarning'>,
'list': <class 'list'>, 'iter': , 'Warning':
<class 'Warning'>, 'package': None, 'round': , 'dir': , 'cmp': ,
'set': <class 'set'>, 'bytes': <class 'bytes'>, 'UnicodeTranslateError':
<class 'UnicodeTranslateError'>, 'issubclass': , 'EOFError': <class 'EOFError'>, 'locals': , 'BufferError': <class 'BufferError'>, 'slice': <class
'slice'>, 'FloatingPointError': <class 'FloatingPointError'>, 'sum':
, 'getattr': , 'abs':
, 'exit': Use exit() or Ctrl-D (i.e. EOF) to
exit, 'print': , 'True': True, 'FutureWarning':
<class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>,
'None': None, 'hash': , 'ReferenceError': <class
'ReferenceError'>, 'len': , 'credits': Thanks
to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more
information., 'frozenset': <class 'frozenset'>, 'name': 'builtins',
'ord': , 'super': <class 'super'>, '_':
Decimal('NaN123'), 'TypeError': <class 'TypeError'>, 'license': Type
license() to see the full license text, 'KeyboardInterrupt': <class
'KeyboardInterrupt'>, 'UserWarning': <class 'UserWarning'>, 'filter':
<class 'filter'>, 'range': <class 'range'>, 'staticmethod': <class
'staticmethod'>, 'SystemError': <class 'SystemError'>, 'BaseException':
<class 'BaseException'>, 'pow': , 'RuntimeError':
<class 'RuntimeError'>, 'float': <class 'float'>, 'MemoryError': <class
'MemoryError'>, 'StopIteration': <class 'StopIteration'>, 'globals':
, 'divmod': ,
'enumerate': <class 'enumerate'>, 'Ellipsis': Ellipsis, 'LookupError':
<class 'LookupError'>, 'open': <class 'io.OpenWrapper'>, 'quit': Use
quit() or Ctrl-D (i.e. EOF) to exit, 'UnicodeError': <class
'UnicodeError'>, 'zip': <class 'zip'>, 'hex': ,
'next': , 'ImportError': <class 'ImportError'>,
'chr': , 'type': <class 'type'>, 'doc':
"Built-in functions, exceptions, and other objects.\n\nNoteworthy: None
is the
nil' object; Ellipsis represents...' in slices.", 'Exception':<class 'Exception'>, 'tuple': <class 'tuple'>, 'reversed': <class
'reversed'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>,
'input': , 'hasattr': , 'delattr': , 'setattr': , 'SyntaxWarning': <class 'SyntaxWarning'>, 'compile':
, 'ArithmeticError': <class
'ArithmeticError'>, 'str': <class 'str'>, 'property': <class
'property'>, 'GeneratorExit': <class 'GeneratorExit'>, 'int': <class
'int'>, 'import': , 'KeyError': <class
'KeyError'>, 'PendingDeprecationWarning': <class
'PendingDeprecationWarning'>, 'EnvironmentError': <class
'EnvironmentError'>, 'ascii': , 'id': , 'OSError': <class 'OSError'>, 'DeprecationWarning': <class
'DeprecationWarning'>, 'min': , 'UnicodeWarning':
<class 'UnicodeWarning'>, 'any': , 'complex':
<class 'complex'>, 'bool': <class 'bool'>, 'ValueError': <class
'ValueError'>, 'NotImplemented': NotImplemented, 'map': <class 'map'>,
'exec': , 'max': ,
'object': <class 'object'>, 'TabError': <class 'TabError'>,
'ZeroDivisionError': <class 'ZeroDivisionError'>, 'eval': , 'debug': True, 'IndentationError': <class
'IndentationError'>, 'AssertionError': <class 'AssertionError'>,
'classmethod': <class 'classmethod'>, 'UnboundLocalError': <class
'UnboundLocalError'>, 'NotImplementedError': <class
'NotImplementedError'>, 'AttributeError': <class 'AttributeError'>,
'OverflowError': <class 'OverflowError'>}, 'file':
'/temp/python/py3k/Lib/test/test_builtin.py', 'BuiltinTest': <class
'test.test_builtin.BuiltinTest'>, 'TestFailingBool': <class
'test.test_builtin.TestFailingBool'>, 'sys': <module 'sys' (built-in)>,
'test': <module 'test' from '/temp/python/py3k/Lib/test/init.py'>,
'name': 'test.test_builtin', 'unlink': <function unlink at
0x7a5540>, 'TESTFN': '@test', 'TestSorted': <class
'test.test_builtin.TestSorted'>, 'BitBucket': <class
'test.test_builtin.BitBucket'>, 'fcmp': <function fcmp at 0x7ad540>}
pitrou commentedon Jul 29, 2008
My wild uneducated guess is that it's due to a nan-like value being in
the globals, and comparing unequal to itself:
amauryfa commentedon Jul 29, 2008
Bingo! doctest sets the __builtins__._ variable, and the last doctest in decimal.py (in lexicographic order) is Decimal.__round__, which ends with >>> round(Decimal('sNaN123'), 0) Decimal('NaN123') This is the value you see in Benjamin's output.Here is a trivial patch:
Index: Lib/test/regrtest.py
===================================================================
--- Lib/test/regrtest.py (revision 65283)
+++ Lib/test/regrtest.py (working copy)
@@ -647,6 +647,8 @@
def cleanup_test_droppings(testname, verbose):
import shutil
+ __builtins__._ = None
+
# Try to clean up junk commonly left behind. While tests shouldn't
leave
# any files or directories behind, when a test fails that can be
tedious
# for it to arrange. The consequences can be especially nasty on
Windows,
benjaminp commentedon Jul 29, 2008
On Tue, Jul 29, 2008 at 8:30 AM, Amaury Forgeot d'Arc <report@bugs.python.org> wrote: > > Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: > > Bingo! doctest sets the __builtins__._ variable, > and the last doctest in decimal.py (in lexicographic order) is > Decimal.__round__, which ends with > >>> round(Decimal('sNaN123'), 0) > Decimal('NaN123') > This is the value you see in Benjamin's output. > > Here is a trivial patch:Shouldn't this be fixed in test_decimal so it cleans properly after it's self?
pitrou commentedon Jul 29, 2008
I think the cleanup should either be in regrtest.py as Amaury proposes,
or in doctest itself. There's nothing wrong in decimal and its test suite.
amauryfa commentedon Jul 29, 2008
I was leaning towards the "doctest should not pollute the __builtins__
module" side.
test_decimal might not be the only test that leaks one object outside
the module.
benjaminp commentedon Jul 29, 2008
I vote for fixing doctest then!
amauryfa commentedon Jul 29, 2008
Here is another patch that modifies doctest itself.
Note that the _ is cleared only if "clear_globs" is True, which makes
sense IMO.
Index: Lib/doctest.py
===================================================================
pitrou commentedon Jul 29, 2008
The doctest patch looks fine to me.
pitrou commentedon Jul 29, 2008
Well except that it would be better spelt as:
__builtins__._ = None
benjaminp commentedon Jul 29, 2008
Ok. Thanks! Applied in r65285.
benjaminp commentedon Jul 29, 2008
On Tue, Jul 29, 2008 at 10:29 AM, Antoine Pitrou <report@bugs.python.org> wrote:
__builtins__ is a dict here, though.
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
amauryfa commentedon Jul 29, 2008
You know what? It's a mess.
The fix is correct for most modules:
./python Lib\test\test_decimal.py
but fails for
./python Lib\doctest.py
pitrou commentedon Jul 29, 2008
Selon Amaury Forgeot d'Arc <report@bugs.python.org>:
(why is it so? :-O)
Anyway:
pitrou commentedon Jul 29, 2008
Ok, I've found it:
« But why is __builtins__ a module in __main__ and a dict elsewhere?
Because in *interactive* mode, printing vars() would include
__builtins__, which would be rather large. Code that incorrectly
assumes it's always one or the other is incorrect and has always been
incorrect; the wart was present when this feature first appeared.
Since this has never been documented AFAIK, it's probably just been
(incorrectly) reverse-engineered and copied around. »
http://mail.python.org/pipermail/python-3000/2007-March/006170.html
:-S
amauryfa commentedon Jul 29, 2008
It is actually documented, at the bottom of
http://docs.python.org/dev/library/__builtin__.html
"import builtin" is the correct thing to do.