A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-February/116773.html below:

[Python-Dev] Exceptions in LOAD_GLOBAL and LOAD_NAME

[Python-Dev] Exceptions in LOAD_GLOBAL and LOAD_NAME [Python-Dev] Exceptions in LOAD_GLOBAL and LOAD_NAMEMark Shannon mark at hotpy.org
Thu Feb 23 11:12:13 CET 2012
The code below causes different behaviour for LOAD_GLOBAL and LOAD_NAME.
Which is correct?
Should exceptions raised in the equality test be converted to a 
NameError or just propogated?

Cheers,
Mark.

-------------------------------------
import sys

class S(str):
     pass

def eq_except(self, other):
     if isinstance(other, str):
         raise TypeError("Cannot compare S and str")

globals()[S("a")] = 0

S.__eq__ = eq_except

def f():
     print(a)

try:
     f()
except:
     print(sys.exc_info()[1])

try:
     print(a)
except:
     print(sys.exc_info()[1])
----------------------------------

Output:

TypeError('Cannot compare S and str',)
NameError("name 'a' is not defined",)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4