durusmail: quixote-users: Generalizing form/widget API a bit
Generalizing form/widget API a bit
2003-11-25
2003-11-25
2003-11-25
2003-11-25
2003-11-25
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-29
2003-11-30
2003-11-26
2003-11-26
2003-11-26
Patch: add html_attrs keyword arg to widget classes
2003-11-30
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
2003-12-02
2003-12-03
2003-12-02
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Generalizing form/widget API a bit
Martin Maney
2003-11-26
On Tue, Nov 25, 2003 at 08:55:05PM -0800, Jim Dukarm wrote:
> ---------- Martin Maney: --------------
> > It's a nasty, inconsistent gimmick, IMO.  Or does it allow for
> > consistent use of the trailing underscore even with non-keywords?
>
> I wonder whether it is even necessary to avoid the word "class" in
> this context, since it is just being used as a dict key and eventually
> gets included in a stream of text.

As a dict key, no, of course not - then it's just a string.  The
context here was using the lazy shorthand trick for writing a literal
dict without quotation marks, as you showed later.  But this has a
problem with keywords exactly because it doesn't use string literals:

def make_dict(**kw):
    return kw

>>> make_dict(foo=1, bar=2)
{'foo': 1, 'bar': 2}
>>> make_dict(foo=1, bar=2, class=3)
  File "", line 1
    make_dict(foo=1, bar=2, class=3)
                                ^
SyntaxError: invalid syntax

Hence the work-around:

>>> make_dict(foo=1, bar=2, class_=3)
{'class_': 3, 'foo': 1, 'bar': 2}

All of which looks like a stupidly clever hack to me, and the need to
decorate the names with underscores to sidestep keywords highlights the
marginality of the gain.  This is not the one [obvious] way to write a
dictionary literal!

> > Lovely idea, but it seems to require more than just 2.2:
>
> You have a point there.

For some reason I didn't think to check the 2.3 library reference until
after sending that off; there it says that the keyword hack was added
in 2.3.

--
There has grown up in the minds of certain groups in this country
the notion that because a man or corporation has made a profit
out of the public for a number of years, the government and the courts
are charged with the duty of guaranteeing such profit in the future,
even in the face of changing circumstances and contrary public interest.
This strange doctrine is not supported by statute nor common law.  -- RAH


reply