Why no warnings when re-assigning builtin names?

Terry Reedy tjreedy at udel.edu
Tue Aug 16 22:15:03 EDT 2011


On 8/16/2011 8:18 PM, Philip Semanchuk wrote:

> Hi Terry,
> To generalize from your example, are you saying that there's a mild admonition
 > against shadowing builtins with unrelated variable names in standard 
lib code?

I would expect that there might be. I would have to check PEP8.

> Here's an example from Python 3.2.1's argparse.py, lines 466-473.
 > "open" is shadowed on the second line.
>
>          # clean up separators for mutually exclusive groups
>          open = r'[\[(]'
>          close = r'[\])]'
>          text = _re.sub(r'(%s) ' % open, r'\1', text)
>          text = _re.sub(r' (%s)' % close, r'\1', text)
>          text = _re.sub(r'%s *%s' % (open, close), r'', text)
>          text = _re.sub(r'\(([^|]*)\)', r'\1', text)
>          text = text.strip()

-- 
Terry Jan Reedy




More information about the Python-list mailing list