Skip to content

Referencing __main__.__builtins__ causes AttributeError #102

@kerrick-js

Description

@kerrick-js

py.ml references __main__.__builtins__ in a couple places. According to the docs, this attribute is an implementation detail and its behavior can't be relied upon:

CPython implementation detail: Users should not touch __builtins__; it is strictly an implementation detail.

This causes problems when running code under pdb. In pdb __main__.__builtins__ is a dict, not a module:

$ echo 'import __main__; print(type(__main__.__builtins__))' > foo.py
$ python3 foo.py
<class 'module'>
$ python3 -m pdb -c c -c q foo.py
<class 'dict'>
The program finished and will be restarted

This causes exceptions like

AttributeError: 'dict' object has no attribute 'SomeBuiltinThing'

when you try to reference attributes on this module.

Instead, py.ml should import the builtins module or reference sys.modules['builtins'].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions