Why no warnings when re-assigning builtin names?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Aug 16 03:32:09 CEST 2011

On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote:

> On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert
> <grickert at coldstorage.com> wrote:
>> With surprising regularity, I see program postings (eg. on StackOverflow)
>> from inexperienced Python users  accidentally re-assigning built-in
>> names.
>> For example, they’ll innocently call some variable, “list”, and assign a
>> list of items to it.
> It's actually masking, not reassigning. That may make it easier or
> harder to resolve the issue.

The usual term is "shadowing builtins", and it's a feature, not a bug :)

> If you want a future directive that deals with it, I'd do it the other
> way - from __future__ import mask_builtin_warning or something - so
> the default remains as it currently is. But this may be a better job
> for a linting script.

Agreed. It's a style issue, nothing else. There's nothing worse about:

def spam(list):

compared to

class thingy: pass

def spam(thingy):

Why should built-ins be treated as more sacred than your own objects?


More information about the Python-list mailing list