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/2002-January/019614.html below:

[Python-Dev] When to signal an error

[Python-Dev] When to signal an errorJason Orendorff jason@jorendorff.com
Sat, 19 Jan 2002 17:16:42 -0600
Neal Norwitz:
> Guido van Rossum:
> > But these warnings will always have a different status than purely
> > syntactical error: there are often cases where the user knows better
> > (for example, sometimes an attribute reference can have a desirable
> > side effect).
>
> I agree.

Here's what Pychecker finds in the standard library (as of 2.2).
In each case, the expression is intended to raise an exception if
the named variable or attribute doesn't exist.

Each one could be rewritten (I'm curious as to the prevailing
stylistic opinions on this):


=== code.py (lines 217 and 221)
        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "
        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "

Could be rewritten:
        if not hasattr(sys, 'ps1'):
            sys.ps1 = ">>> "
        if not hasattr(sys, 'ps2'):
            sys.ps2 = "... "

=== locale.py (line 721)
try:
    LC_MESSAGES
except:
    pass
else:
    __all__.append("LC_MESSAGES")

Could be rewritten:
if globals().has_key("LC_MESSAGES"):
    __all__.append("LC_MESSAGES")

=== pickle.py (line 58)
try:
    UnicodeType
except NameError:
    UnicodeType = None

Could be rewritten:
globals().setdefault('UnicodeType', None)

## Jason Orendorff    http://www.jorendorff.com/



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