Yes, I'd expect the keys to be newstr, since that would match python3
behavior.
Here's my udict:
def udict(*args, **kwargs):
"""Similar to dict(), but keyword-keys are text.
TODO: refactor out udict in favor of future.newdict
"""
kwargs = dict([
(u(key), val)
for key, val in kwargs.items()
])
return dict(*args, **kwargs)
Post by Buck GolemonAs I understand it, the contract of future.builtins is to act like the
python3 builtins, but this behavior is distinctly python2-ish (and
necessitates me to write my own `udict`).
dict
<class 'future.builtins.types.newdict.newdict'>
type(tuple(dict(a=1).keys())[0]).mro()
[<type 'str'>, <type 'basestring'>, <type 'objectâ>]
Hi Buck,
Yes, the type of âaâ is a native string. This seems to be what Python does
when passing a kwarg to a function. Can you think of a way around this?
What would you prefer to happen instead? Would you prefer for
``dict(a=1)`` to give you a dict with a ``newstr`` as the key? What is the
application you have in mind?
I would be interested in seeing your ``udict`` class to consider whether
``future.types.newdict`` can be modified to meet this need.
Best wishes,
Ed
--
Dr. Edward Schofield
Python Charmers
http://pythoncharmers.com