Skip to content

The execution environment ptipython uses with the “-i” flag doesn’t appear as IPython’s #340

@fish2000

Description

@fish2000

I’ve produced a minimal example. Basically:

«develop»:PIPER-ECHO:clu[master •]$ cat /tmp/ipythonvariable.py 
try:
    __IPYTHON__
except NameError:
    IPYTHON = False
else:
    IPYTHON = True
«develop»:PIPER-ECHO:clu[master •]$ ptipython -i /tmp/ipythonvariable.py 
/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py:935: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.7.6 (default, Dec 30 2019, 19:38:28) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: __IPYTHON__                                                                                  
Out[1]: True
In [2]: IPYTHON                                                                                      
Out[2]: False
In [3]: quit                                                                                         
«develop»:PIPER-ECHO:clu[master •]$ 

Screen Shot 2020-02-07 at 9 28 26 PM

… in this case, the variable IPYTHON should evaluate to True, as it does when python -m IPython -i /tmp/ipythonvariable.py is run – because the special variable __IPYTHON__ is defined by IPython in the global namespace whenever it is running.

… It looks like ptpython runs the script named with “-i” before initializing the IPython environment, or somesuch – I briefly skimmed through the ptpython codebase but I’m not a REPL expert or an IPython guru or any of that, so this is just what I can surmise.

Either way it seems like a bug – the “-i” flag ought to behave as it does with vanilla IPython, n’est ce pas? I feel as though it ought. Yes.

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