[Python-ideas] [Python-Ideas] Set the namespace free!

Nick Coghlan ncoghlan at gmail.com
Fri Jul 23 12:39:27 CEST 2010

(moving to python-ideas, where this discussion belongs)

On Fri, Jul 23, 2010 at 7:01 AM,  <gregory.smith3 at sympatico.ca> wrote:
>> Date: Thu, 22 Jul 2010 14:49:17 -0400
>> Subject: Re: [Python-Dev] Set the namespace free!
>> From: alexander.belopolsky at gmail.com
>> To: gregory.smith3 at sympatico.ca
>> CC: python-dev at python.org
>> On Thu, Jul 22, 2010 at 12:53 PM, <gregory.smith3 at sympatico.ca> wrote:
>> ..
>> > So, ::name or &name or |name or whatever.
>> >
>> > I'm very amused by all the jokes about turning python into perl, but
>> > there's
>> > a good idea here that doesn't actually require that...
>> No, there isn't. And both '&' and '|' are valid python operators that
>> cannot be used this way.
> Um, of course. Serious brain freeze today, using too many languages at once.
> Yeah, that's it.
> Despite my knuckleheadedness, I say there's still a hole here that can be
> easily plugged. it's clumsy that you can't call, e.g.
> GenerateURL( reqtype='basic', class='local')
> other than by
> GenerateURL(  **{'reqtype': 'basic', 'class': 'local'})
> ... just because 'class' is a keyword.  That's letting a parser issue
> degrade the value of a really good feature. Likewise for attributes; python
> allows you to have
> named parameters or attributes called 'class' and 'import' if you like; it
> just doesn't let you write them directly; this restriction doesn't seem to
> be necessary except for the parse issue, which is fixable. I.e. nothing
> would break by allowing GenerateURL(::class = 'local') or
> Request.::class.

Or, rather than making a major syntactic change that affects not just
all Python implementations, but also every syntax highlighter that
understands the set of reserved words, we instead encourage external
interface developers to implement three simple rules:

1. If a name coming from an external resource clashes with a Python
keyword, append a single underscore
2. If a name coming from an external resource ends with an underscore,
append an additional underscore
3. If a name being written to or otherwise used to access an external
resource ends with an underscore, remove it

The above example would then be written as:

GenerateURL( reqtype='basic', class_='local')

Why should the entire language toolset be burdened with additional
syntax in order to deal with an issue that could be handled perfectly
well by the adoption of some simple API conventions?


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list