Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDisplay dict of namedtuples #230
Comments
|
BTW, it would be probably a good idea to display namedtuple itself like a dict, but then this somewhat depends on what namedtuples are commonly used for. Mine would be more readable with field labels. |
|
Good idea. The relevant code to change is: Lines 258 to 261 in c830177 and python-fire/fire/value_types.py Line 44 in c830177 |
|
I've been working on this issue for a while.I think that namedtuples are not correctly handled yet. |
I just confirmed in Python 3:
Where did you see a namedtuple that was not an instance of tuple?
Are there other collections or types you're thinking about? We don't have a clearly articulated scope. NamedTuples are important to handle well because they're commonly used. |
Yes. You're right. I made a mistake in passing the right variable to it.
I've used typing.NamedTuple before. Which is a typed version of collection.namedtuple:(https://docs.python.org/3/library/typing.html#typing.NamedTuple) It's Handled well here, like a collections.namedtuple object. |
|
@dbieber |
Fire nicely prints a dict of dicts using one line per inner dict. When I try to do the same with dict of namedtuples (which otherwise behave like dicts after #161), I just get a help page listing all the dict keys. When I specify a dict key, then that namedtuple is printed. I would prefer all namedtuples in the dict to be printed when no key is specified.