Should Python raise a warning for mutable default arguments?

George Sakkis george.sakkis at gmail.com
Sat Aug 23 05:13:49 CEST 2008


On Aug 22, 9:54 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:

> On Fri, 22 Aug 2008 14:39:11 -0700, Emile van Sebille wrote:
> > Dan wrote:
> >> I'd suggest that at the
> >> end of the tutorial, when people have a better general idea of how
> >> Python works, there would be a Python Gotchas section.
>
> > Hmmm, OK -- mutable defaults, integer division, name mangling...
>
> > I'd think decimal precision is more a general problem than a python
> > problem, but still one that throws newbies...
>
> > Any other ideas for gotcha's (as opposed to faqs)?
>
> Augmented assignment: x ?= y is not always the same as x = x ? y.
>
> Repeated string addition can be very slow. For that matter, so can list
> addition.
>
> Inserting at the beginning of lists is slow.
>
> Everything about unicode is a Gotcha! *wink*
>
> Raw strings are not designed for Windows paths, they're designed for
> regexes. Consequently, you can't write the following:
>
> r'C:\dir\'
>
> list.sort() and list.reverse() return None.
>
> sorted() returns a list, but reversed() returns an iterator.
>
> urllib2.urlopen() will automatically detect the proxy in your environment
> and use that. That's usually a feature, but sometimes it can be a gotcha.
>
> urllib2 doesn't work well with some HTTPS proxies. This is, I believe, a
> known bug, but until it is fixed, it can be a gotcha.

My "favorite": comparisons between disparate types are allowed by
default. Thankfully fixed in 3.0.

George



More information about the Python-list mailing list