Skip to content

'__console__' instead of '__main__' as __name__ in bpython 0.20.1 #868

Closed

Description

@colomb8

this works:

(py3) DC@bdd14:~/code/stable$ bpython
bpython version 0.20.1 on top of Python 3.8.5 /home/.../miniconda3/envs/py3/bin/python
>>> __name__
'__main__'

but this doesn't:

(py3) DC@bdd14:~/code/stable$ bpython -i main.py
bpython version 0.20.1 on top of Python 3.8.5 /home/.../miniconda3/envs/py3/bin/python
>>> __name__
'__console__'

Activity

  1. vmdhhh commented on Dec 22, 2020

    @vmdhhh

    @sebastinas After a brief debugging, I found out that the __name__ is getting changed to __console__ in __main__.py.
    And as we are importing the main, it gives __console__.
    Sorry if this sounds obvious/rubbish as I am not a pro, but if you could direct me towards something, I would like to help.

    Edit: Little more digging and I think this is because of a Helper to execute code in a given interpreter in args.py as we are loading specs from __console__. Looks like expected behaviour.

  2. sebastinas commented on Dec 31, 2020

    @sebastinas
    Contributor

    The behavior should be consistent with the vanilla Python interpreter. Whatever it does, should be emulated here.

  3. vmdhhh commented on Jan 1, 2021

    @vmdhhh

    The behavior should be consistent with the vanilla Python interpreter. Whatever it does, should be emulated here.

    @sebastinas Does this mean that the __name__ should output __main__ everywhere?

  4. colomb8 commented on Jan 2, 2021

    @colomb8
    Author

    The behavior should be consistent with the vanilla Python interpreter. Whatever it does, should be emulated here.

    @sebastinas Does this mean that the __name__ should output __main__ everywhere?

    no, only in the main script, while in the others should return the name of each module

  5. sebastinas commented on Jan 8, 2021

    @sebastinas
    Contributor

    python has the following behavior:

    % cat pm.py 
    print(__name__)
    % python3 pm.py
    __main__
    % python3 -i pm.py
    __main__
    >>> print(__name__)
    __main__
    % python3
    >>> print(__name__)
    __main__
    

    __name__ is set to __console__ by code.InteractiveInterpreterby default. I don't remeber if there was a specific reasons to keep this behavior. I think that we should align bpython's behavior with that of python.

  6. sebastinas commented on May 2, 2022

    @sebastinas
    Contributor

    Fixed in 14669c0.

  7. added this to the release-0.23 milestone on May 2, 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions