[issue32854] Add ** Map Unpacking Support for namedtuple

2018-02-15 Thread John Crawford

New submission from John Crawford <jtcrw...@gmail.com>:

At present, `collections.namedtuple` does not support `**` map unpacking 
despite being a mapping style data structure.  For example:

>>> from collections import namedtuple
>>> A = namedtuple("A", "a b c")
>>> a = A(10, 20, 30)
>>> def t(*args, **kwargs):
... print(f'args={args!r}, kwargs={kwargs!r}')
...
>>> t(*a)
args=(10, 20, 30), kwargs={}
>>> t(**a)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: t() argument after ** must be a mapping, not A
>>> 

No doubt, the lack of current support is due to namespace conflicts that result 
from trying to provide a `keys` method amidst also supporting attribute-style 
access to the `namedtuple` class.  As we can see, providing a `keys` attribute 
in the `namedtuple` produces an interesting result:

>>> Record = namedtuple("Record", "title keys description")
>>> t(**Record(1, 2, 3))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: attribute of type 'int' is not callable
>>>

To me, this calls out a design flaw in the `**` unpacking operator where it 
depends on a method that uses a non-system naming convention.  It would make 
far more sense for the `**` operator to utilize a `__keys__` method rather than 
the current `keys` method.  After all, the `____` naming convention 
was introduced to avoid namespace conflict problems like this one.

--
components: Library (Lib)
messages: 312218
nosy: John Crawford
priority: normal
severity: normal
status: open
title: Add ** Map Unpacking Support for namedtuple
type: enhancement
versions: Python 3.7, Python 3.8

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32854>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Python/Django forum-building software Snap/SCT, any reviews?

2009-03-12 Thread John Crawford
I'm looking for good open-source software for forums. There is a *lot* out 
there, for instance Lussumo's Vanilla gets good reviews, but most are 
PHP-based, and I would obviously prefer to use Python, with or without Django. 

Two packages that are Django-based that I have found, are Snap and SCT. They 
both look pretty good (and Snap was influenced by Vanilla). Does anyone have 
any experience with these packages, and comments about them? Thanks

John C
For all your days, prepare, and meet them ever alike;
When you are the anvil, bear - when the hammer, strike.

Posted with NewzToolz. Free RAR, PAR, and yEnc decoders.
Get your free copy at www.techsono.com.



--
http://mail.python.org/mailman/listinfo/python-list