Plural from of attr

6 views
Skip to first unread message

Andrew Svetlov

unread,
Aug 5, 2009, 9:49:10 AM8/5/09
to Better Python
I think a lot about plural component attribute definitions like attrs,
todo.attrs, track.attrs etc.
From my perspective implementation is a bit tricky. But it's not main
problem. Definition like
class A(Component):
attrs(a=1, b=2, c='abc')

is not pythonic. I never seen this notation anywhere. Really it's
implicit modification of outer scope with limitations (you can specify
only one value per attribute).
Maybe it can save couple of lines but breaks one of python rules -
program text should be obvious.

ORMs and webforms processors uses metadata to build classes but this
is another use case from my perspective.

Sergey Schetinin

unread,
Aug 5, 2009, 2:16:54 PM8/5/09
to better...@googlegroups.com
I agree in general, but there a few cases when this non-pythonic form
makes code much more readable. I wouldn't encourage it too much, but
I'm not sure splitting statements like following into multiple attrs
is a good idea:

attrs(
title = '',
menu = None,
statusbar = None,
allow_resize=True, allow_maximize=True,
posx=50, posy=100, #@@
minimized=False, maximized=False, #@@
initial_width=None, initial_height=None,
)

The implementation is a hack, but there are real cases where win is so
big I'd rather let it stay.
--
Best Regards,
Sergey Schetinin

http://s3bk.com/ -- S3 Backup
http://word-to-html.com/ -- Word to HTML Converter
Reply all
Reply to author
Forward
0 new messages