[IPython-dev] "__builtins__.True = False" causes weird behaviours

Gökhan Sever gokhansever at gmail.com
Sun Nov 8 13:09:42 EST 2009


On Sat, Nov 7, 2009 at 11:34 PM, Brian Granger <ellisonbg.net at gmail.com>wrote:

> He he.  The good news is that trunk fixes most of this...
>
> In [2]: __builtins__.True = False
>
> In [3]: __builtins__.True == False
> Out[3]: True
>
> But exiting doesn't work:
>
> In [4]: Exit
>
> In [5]:
>
> The reason exiting doesn't work is that ask_exit is called by Exit, exit()
> and quit():
>
>     def ask_exit(self):
>         """ Call for exiting. Can be overiden and used as a callback. """
>         self.exit_now = True
>
> But if True is False, self.exit_now won't trigger the exit.
>
> The funny thing is that doing the opposite really screws things up:
>
> In [1]: __builtins__.False = True
>    ...:
>    ...:
>    ...:
>    ...:
>    ...:   # stuck  forever indented...
>
> But, just because you can hit your head with a hammer, doesn't mean you
> should...;-)
>
> Cheers,
>
> Brian
>
>
>
Good morning :)

How do you fix these in the trunk? Raising an exception if a user enters any
of the forbidden assignments ?

Fortunately not many out who has the obsession of defining True as False.
Somewhat I connect this to Wittgenstein's belief that "There are no
philosophical questions, but only language puzzles."



>
> On Sat, Nov 7, 2009 at 8:56 PM, Gökhan Sever <gokhansever at gmail.com>wrote:
>
>> Hello,
>>
>> After reading the "Breaking the Universe in Python 2.6" section (Pg. 414)
>> in Mark Lutz's Learning Python 4th Edition. Two issues appeared as shown
>> below:
>> *
>> 1-) If I start ipython -pylab the mentioned assignment completely blocks
>> the session. Only stopping or killing the process ends the current session.
>> *
>>
>> [gsever at ccn Desktop]$ ipython -pylab
>>  Logging to /home/gsever/.ipython/2009-11-07.py
>>
>> Python 2.6 (r26:66714, Jun  8 2009, 16:07:26)
>> Type "copyright", "credits" or "license" for more information.
>>
>> IPython 0.10 -- An enhanced Interactive Python.
>> ?         -> Introduction and overview of IPython's features.
>> %quickref -> Quick reference.
>> help      -> Python's own help system.
>> object?   -> Details about 'object'. ?object also works, ?? prints more.
>>
>>   Welcome to pylab, a matplotlib-based Python environment.
>>   For more information, type 'help(pylab)'.
>>
>> I[1]: __builtins__.True = False
>> Exception in thread Thread-1:
>> Traceback (most recent call last):
>>   File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner
>>     self.run()
>>   File "/home/gsever/Desktop/python-repo/ipython/IPython/Shell.py", line
>> 760, in run
>>     self.IP.mainloop(self._banner)
>>   File "/home/gsever/Desktop/python-repo/ipython/IPython/iplib.py", line
>> 1760, in mainloop
>>     self.interact(banner)
>>   File "/home/gsever/Desktop/python-repo/ipython/IPython/iplib.py", line
>> 1998, in interact
>>     more = self.push(line)
>>   File "/home/gsever/Desktop/python-repo/ipython/IPython/iplib.py", line
>> 2302, in push
>>     more = self.runsource('\n'.join(self.buffer), self.filename)
>>   File "/home/gsever/Desktop/python-repo/ipython/IPython/Shell.py", line
>> 431, in runsource
>>     completed_ev.wait()
>>   File "/usr/lib/python2.6/threading.py", line 393, in wait
>>     self.__cond.wait(timeout)
>>   File "/usr/lib/python2.6/threading.py", line 230, in wait
>>     raise RuntimeError("cannot wait on un-aquired lock")
>> RuntimeError: cannot wait on un-aquired lock
>>
>> Unhandled exception in thread started by <bound method
>> IPShellMatplotlibQt4.__bootstrap of <IPShellMatplotlibQt4(Thread-1, started
>> -1230734480)>>
>>
>> ---------------------------------------------------------------------------
>> RuntimeError                              Traceback (most recent call
>> last)
>>
>> /usr/lib/python2.6/threading.pyc in __bootstrap(self)
>>     495         # if a non-daemonic encounters this, something else is
>> wrong.
>>
>>     496         try:
>> --> 497             self.__bootstrap_inner()
>>     498         except:
>>     499             if self.__daemonic and _sys is None:
>>
>> /usr/lib/python2.6/threading.pyc in __bootstrap_inner(self)
>>     568         finally:
>>     569             with _active_limbo_lock:
>> --> 570                 self.__stop()
>>     571                 try:
>>     572                     # We don't call self.__delete() because it
>> also
>>
>>
>> /usr/lib/python2.6/threading.pyc in __stop(self)
>>     579         self.__block.acquire()
>>     580         self.__stopped = True
>> --> 581         self.__block.notify_all()
>>     582         self.__block.release()
>>     583
>>
>> /usr/lib/python2.6/threading.pyc in notifyAll(self)
>>     287
>>     288     def notifyAll(self):
>> --> 289         self.notify(len(self.__waiters))
>>     290
>>     291     notify_all = notifyAll
>>
>> /usr/lib/python2.6/threading.pyc in notify(self, n)
>>     270     def notify(self, n=1):
>>     271         if not self._is_owned():
>> --> 272             raise RuntimeError("cannot notify on un-aquired lock")
>>     273         __waiters = self.__waiters
>>     274         waiters = __waiters[:n]
>>
>> RuntimeError: cannot notify on un-aquired
>> lock---------------------------------------------------------------------------
>> RuntimeError                              Traceback (most recent call
>> last)
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/Shell.pyc in
>> on_timer(self)
>>    1075     def on_timer(self):
>>    1076         update_tk(self.tk)
>> -> 1077         result = self.IP.runcode()
>>    1078         self.timer.start(self.TIMEOUT)
>>    1079         return result
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/Shell.pyc in
>> runcode(self)
>>     491                 CODE_RUN = False
>>     492                 # allow runsource() return from wait
>>
>> --> 493                 completed_ev.set()
>>     494
>>     495
>>
>> /usr/lib/python2.6/threading.pyc in set(self)
>>     376         try:
>>     377             self.__flag = True
>> --> 378             self.__cond.notify_all()
>>     379         finally:
>>     380             self.__cond.release()
>>
>> /usr/lib/python2.6/threading.pyc in notifyAll(self)
>>     287
>>     288     def notifyAll(self):
>> --> 289         self.notify(len(self.__waiters))
>>     290
>>     291     notify_all = notifyAll
>>
>> /usr/lib/python2.6/threading.pyc in notify(self, n)
>>     270     def notify(self, n=1):
>>     271         if not self._is_owned():
>> --> 272             raise RuntimeError("cannot notify on un-aquired lock")
>>     273         __waiters = self.__waiters
>>     274         waiters = __waiters[:n]
>>
>> RuntimeError: cannot notify on un-aquired lock
>>
>> *
>> 2-) Testing just with regular ipython. This time it gets even more
>> bizarre. *
>>
>> In[1] It lets to do the assignment.
>> In[2] A simple calculation results ok
>> In[3] Tab-completion is blocked
>> In[4] ? cannot retrieve the documentation
>> In[5] exit() doesn't leave the session
>>
>> [gsever at ccn Desktop]$ ipython
>>  Logging to /home/gsever/.ipython/2009-11-07.py
>>
>> Python 2.6 (r26:66714, Jun  8 2009, 16:07:26)
>> Type "copyright", "credits" or "license" for more information.
>>
>> IPython 0.10 -- An enhanced Interactive Python.
>> ?         -> Introduction and overview of IPython's features.
>> %quickref -> Quick reference.
>> help      -> Python's own help system.
>> object?   -> Details about 'object'. ?object also works, ?? prints more.
>>
>> I[1]: __builtins__.True = False
>>
>> I[2]: 2*5
>> O[2]: 10
>>
>> I[3]: import a
>>
>> ---------------------------------------------------------------------------
>> ImportError                               Traceback (most recent call
>> last)
>>
>> /home/gsever/Desktop/<ipython console> in <module>()
>>
>> ImportError: No module named a
>>
>> I[4]: __builtins__.?
>>
>> ---------------------------------------------------------------------------
>> KeyError                                  Traceback (most recent call
>> last)
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/iplib.pyc in
>> multiline_prefilter(self, line, continue_prompt)
>>    2456         out = []
>>    2457         for l in line.rstrip('\n').split('\n'):
>> -> 2458             out.append(self._prefilter(l, continue_prompt))
>>    2459         return '\n'.join(out)
>>    2460
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/iplib.pyc in
>> _prefilter(self, line, continue_prompt)
>>    2438         #print 'pre <%s> iFun <%s> rest <%s>' %
>> (pre,iFun,theRest)  # dbg
>>
>>    2439
>> -> 2440         return prefilter.prefilter(line_info, self)
>>    2441
>>    2442
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/prefilter.pyc in
>> prefilter(line_info, ip)
>>     149         handler = check(line_info, ip)
>>     150         if handler:
>> --> 151             return handler(line_info)
>>     152
>>     153     return ip.handle_normal(line_info)
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/iplib.pyc in
>> handle_help(self, line_info)
>>    2627             if line:
>>    2628                 #print 'line:<%r>' % line  # dbg
>>
>> -> 2629                 self.magic_pinfo(line)
>>    2630             else:
>>    2631
>> page(self.usage,screen_lines=self.rc.screen_length)
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/Magic.pyc in
>> magic_pinfo(self, parameter_s, namespaces)
>>     658         else:
>>     659             self._inspect('pinfo', oname,
>> detail_level=detail_level,
>>
>> *** ERROR: EOF in multi-line statement
>>
>> --> 660                           namespaces=namespaces)
>>
>> *** ERROR: EOF in multi-line statement
>>
>>     661
>>     662     def magic_pdef(self, parameter_s='', namespaces=None):
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/Magic.pyc in
>> _inspect(self, meth, oname, namespaces, **kw)
>>     714             return 'not found'
>>     715
>> --> 716         info = Struct(self._ofind(oname, namespaces))
>>     717
>>     718         if info.found:
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/ipstruct.pyc in
>> __init__(self, dict, **kw)
>>     125         # safety-checked __setitem__
>>
>>     126         for k,v in dict.items():
>> --> 127             self[k] = v
>>     128
>>     129
>>
>> /home/gsever/Desktop/python-repo/ipython/IPython/ipstruct.pyc in
>> __setitem__(self, key, value)
>>     135             raise KeyError(
>>
>> *** ERROR: EOF in multi-line statement
>>
>>     136             "Can't create unknown attribute %s - Check for typos,
>> or use allow_new_attr to create new attributes!" %
>> --> 137             key)
>>
>> *** ERROR: EOF in multi-line statement
>>
>>     138
>>     139         self.__dict__[key] = value
>>
>> KeyError: "Can't create unknown attribute obj - Check for typos, or use
>> allow_new_attr to create new attributes!"
>>
>> I[5]: exit()
>> Do you really want to exit ([y]/n)? y
>>
>> I[6]: # Still in IPython
>>
>>
>> *3) Using the default interpreter:*
>>
>> [gsever at ccn Desktop]$ python
>> Python 2.6 (r26:66714, Jun  8 2009, 16:07:26)
>> [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> __builtins__.True = False
>> >>> __builtins__.True == True
>> True
>> >>> True == False
>> True
>>
>> The book says this type of assignment is not allowed in Python 3. So far,
>> this is the weirdest issue I have ever seen relating to the IPython.
>>
>> --
>> Gökhan
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>


-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20091108/d98a3a6d/attachment.html>


More information about the IPython-dev mailing list