Skip to content

test_builtin fails after test_decimal #47712

Closed

Description

@benjaminp
BPO 3462
Nosy @amauryfa, @pitrou, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-07-29.15:35:37.456>
created_at = <Date 2008-07-29.02:06:34.619>
labels = ['tests', 'type-bug', 'library']
title = 'test_builtin fails after test_decimal'
updated_at = <Date 2008-07-29.16:02:12.854>
user = 'https://github.com/benjaminp'

bugs.python.org fields:

activity = <Date 2008-07-29.16:02:12.854>
actor = 'amaury.forgeotdarc'
assignee = 'none'
closed = True
closed_date = <Date 2008-07-29.15:35:37.456>
closer = 'benjamin.peterson'
components = ['Library (Lib)', 'Tests']
creation = <Date 2008-07-29.02:06:34.619>
creator = 'benjamin.peterson'
dependencies = []
files = []
hgrepos = []
issue_num = 3462
keywords = []
message_count = 16.0
messages = ['70374', '70387', '70391', '70392', '70393', '70394', '70395', '70396', '70398', '70399', '70400', '70401', '70402', '70403', '70404', '70405']
nosy_count = 3.0
nosy_names = ['amaury.forgeotdarc', 'pitrou', 'benjamin.peterson']
pr_nums = []
priority = 'critical'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue3462'
versions = ['Python 3.0']

Activity

  1. benjaminp commented on Jul 29, 2008

    @benjaminp
    ContributorAuthor

    In Py3k:

    $ ./python Lib/test/regrtest.py test_decimal test_builtin
    test_decimal
    test_builtin
    test test_builtin failed -- Traceback (most recent call last):
      File "Lib/test/regrtest.py", line 603, in runtest_inner
        indirect_test()
      File "/temp/python/py3k/Lib/test/test_builtin.py", line 1252, in test_main
        run_unittest(*test_classes)
      File "/temp/python/py3k/Lib/test/support.py", line 717, in run_unittest
        _run_suite(suite)
      File "/temp/python/py3k/Lib/test/support.py", line 700, in _run_suite
        raise TestFailed(err)
    test.support.TestFailed: Traceback (most recent call last):
      File "/temp/python/py3k/Lib/test/test_builtin.py", line 390, in
    test_general_eval
        self.assertEqual(eval('globals()', g, m), g)
    AssertionError: {'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': <built-in
    function 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':
    <built-in function all>, 'help': Type help() for interactive help, or
    help(object) for help about object., 'vars': <built-in function vars>,
    'SyntaxError': <class 'SyntaxError'>, 'UnicodeDecodeError': <class
    'UnicodeDecodeError'>, 'memoryview': <class 'memoryview'>, 'isinstance':
    <built-in function isinstance>, '__build_class__': <built-in function
    __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>} !=
    {'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>}

    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_inner
        print("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 encode
        return codecs.ascii_encode(input, self.errors)[0]
    UnicodeEncodeError: 'ascii' codec can't encode characters in position
    697-699: ordinal not in range(128)
  2. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    My wild uneducated guess is that it's due to a nan-like value being in
    the globals, and comparing unequal to itself:

    >>> d = {1: float('nan')}
    >>> d
    {1: nan}
    >>> d == d
    False
    >>> import decimal
    >>> nan = decimal.Decimal('nan')
    >>> d = {1: nan}
    >>> d == d
    False
  3. amauryfa commented on Jul 29, 2008

    @amauryfa
    Contributor
    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,

  4. benjaminp commented on Jul 29, 2008

    @benjaminp
    ContributorAuthor
    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?

  5. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    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.

  6. amauryfa commented on Jul 29, 2008

    @amauryfa
    Contributor

    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.

  7. benjaminp commented on Jul 29, 2008

    @benjaminp
    ContributorAuthor

    I vote for fixing doctest then!

  8. added
    stdlibStandard Library Python modules in the Lib/ directory
    testsTests in the Lib/test dir
    type-bugAn unexpected behavior, bug, or error
    on Jul 29, 2008
  9. amauryfa commented on Jul 29, 2008

    @amauryfa
    Contributor

    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
    ===================================================================

    --- Lib/doctest.py      (revision 65283)
    +++ Lib/doctest.py      (working copy)
    @@ -1360,6 +1360,7 @@
                 linecache.getlines = self.save_linecache_getlines
                 if clear_globs:
                     test.globs.clear()
    +                __builtins__['_'] = None
     #/////////////////////////////////////////////////////////////////
     # Summarization
    
  10. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    The doctest patch looks fine to me.

  11. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    Well except that it would be better spelt as:
    __builtins__._ = None

  12. benjaminp commented on Jul 29, 2008

    @benjaminp
    ContributorAuthor

    Ok. Thanks! Applied in r65285.

  13. benjaminp commented on Jul 29, 2008

    @benjaminp
    ContributorAuthor

    On Tue, Jul 29, 2008 at 10:29 AM, Antoine Pitrou <report@bugs.python.org> wrote:

    Antoine Pitrou <pitrou@free.fr> added the comment:

    Well except that it would be better spelt as:
    __builtins__._ = None

    __builtins__ is a dict here, though.


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue3462\>


    --
    Cheers,
    Benjamin Peterson
    "There's no place like 127.0.0.1."

  14. amauryfa commented on Jul 29, 2008

    @amauryfa
    Contributor

    You know what? It's a mess.

    • from the __main__ module, __builtins__ is a module.
    • in all other modules, __builtins__ is a dict.

    The fix is correct for most modules:
    ./python Lib\test\test_decimal.py
    but fails for
    ./python Lib\doctest.py

  15. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    Selon Amaury Forgeot d'Arc <report@bugs.python.org>:

    You know what? It's a mess.

    • from the __main__ module, __builtins__ is a module.
    • in all other modules, __builtins__ is a dict.

    (why is it so? :-O)

    Anyway:

        import builtins as b
        b._ = None
  16. pitrou commented on Jul 29, 2008

    @pitrou
    Member

    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

  17. amauryfa commented on Jul 29, 2008

    @amauryfa
    Contributor

    It is actually documented, at the bottom of
    http://docs.python.org/dev/library/__builtin__.html

    "import builtin" is the correct thing to do.

  18. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions