[ python-Bugs-1113984 ] keywords in keyword_arguments not possible

SourceForge.net noreply at sourceforge.net
Tue Feb 1 21:13:54 CET 2005


Bugs item #1113984, was opened at 2005-02-01 08:47
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1113984&group_id=5470

Category: Parser/Compiler
Group: Python 2.4
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Christoph Zwerschke (cito)
Assigned to: Nobody/Anonymous (nobody)
Summary: keywords in keyword_arguments not possible

Initial Comment:
Currently it is not possible to use keywords in
expressions of the type "keyword_arguments". Example:

d  = {'fi': 1, 'if': 1}

d.update(fi = 2) # ok
d.update(if = 2) # error

If possible, this restriction should be removed.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-02-01 15:13

Message:
Logged In: YES 
user_id=80475

I have no doubt that there are good use cases, your included.

The two issues are that it would complicate the snot out of
parsing (not a good thing) and that allowing keywords in
non-keyword roles would throw-off many existing tools (esp.
syntax highlighters).  

In addition, human eye parsing also suffers when keywords
can be used in non-keyword roles.  IOW, readability suffers.

For your app, it is a reasonable solution to wrap your code
with in preprocessing that converts keywords to non-keywords:

    s = s.replace('class=', '_class=')


----------------------------------------------------------------------

Comment By: Christoph Zwerschke (cito)
Date: 2005-02-01 13:49

Message:
Logged In: YES 
user_id=193957

Maybe I should explain my motivation for making this request.

In Kid [http://kid-template.sf.net], a xml templating
language, it is possible to set xml attributes with a
Pythonic syntax, like this:

<p py:attrs="class=myclass, bgcolor=mycolor, id=173" />

This expression is dynamically evaluated. If
myclass="aclass" and bgcolor="blue", then this would produce
the following:

<p class="aclass" bgcolor="blue" id="173">

Internally, this is of course realized by creating a
dictionary that contains the attributes of the tag, and then
creating an update statement with the string in py:attrs as
argument.

The problem arises when one of the attributes is a Python
keyword, "class" being a particularly embarassing example.

My current solution is to parse the py:attrs expression
manually and mangle the names. If Python could handle Python
keywords here, it would be a whole lot easier and faster.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-02-01 12:46

Message:
Logged In: YES 
user_id=80475

It's possible, but hard to implement and unwise in any case.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1113984&group_id=5470


More information about the Python-bugs-list mailing list