Skip to content

sys.__dict__ gets strange result #11466

Description

@yunkya2

I found sys.__dict__ gets strange result.

>>> import sys
>>> sys.__dict__
{'__name__': 'sys', 'path': ['', '.frozen', '/home/nakamura/.micropython/lib', '/usr/lib/micropython'], 'argv': [], 'version': '3.4.0; MicroPython v1.20.0-62-g4e4bdbd19 on 2023-05-11', 'version_info': (3, 4, 0), 'implementation': (name='micropython', version=(1, 20, 0), _machine='linux [GCC 9.4.0] version', _mpy=2310), 'platform': 'linux', 'byteorder': 'little', 'maxsize': 9223372036854775807, 'exit': <function>, 'stdin': <io.TextIOWrapper 0>, 'stdout': <io.TextIOWrapper 1>, 'stderr': <io.TextIOWrapper 2>, 'modules': {}, 'exc_info': <function>, 'executable': '/home/nakamura/tmp/micropython', 'print_exception': <function>, 'atexit': <function>, '': 46951508960406}

The last item '': 46951508960406 does not exist in sys module in fact.
It is because dict_print tries to print MP_MODULE_ATTR_DELEGATION_ENTRY, the last element of the rom map of sys module.
Similar issue to #8816.

And, by the same reason, we cannot get sys.ps1/ps2 by using __dict__.

>>> sys.__dict__['version']
'3.4.0; MicroPython v1.20.0-62-g4e4bdbd19 on 2023-05-11'
>>> sys.__dict__['ps1']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: ps1

Activity

  1. added
    py-coreRelates to py/ directory in source
    on Aug 1, 2026
  2. agatti commented on Aug 1, 2026

    @agatti
    Contributor

    The first issue seems to have been resolved, all entries in sys.__dict__ look correct now.

    ps1 and ps2 do not appear in sys.__dict__ so it sort of makes sense they fail to be looked up? Those two variables not being there may be seen as a minor incompatibility with CPython, but probably not worth fixing as ps1 and ps2 can still be accessed via sys.ps1 and sys.ps2 respectively.

  3. added a commit that references this issue on Sep 25, 2026
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

    bugproposed-closeSuggest this issue should be closedpy-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions