[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2020-10-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Other problem is that the repr looks like an evaluable expression, but 
evaluating it will always produce error.

>>> st = os.stat('/dev/null')
>>> st
os.stat_result(st_mode=8630, st_ino=6, st_dev=6, st_nlink=1, st_uid=0, 
st_gid=0, st_size=0, st_atime=1602523313, st_mtime=1602523313, 
st_ctime=1602523313)
>>> os.stat_result(st_mode=8630, st_ino=6, st_dev=6, st_nlink=1, st_uid=0, 
>>> st_gid=0, st_size=0, st_atime=1602523313, st_mtime=1602523313, 
>>> st_ctime=1602523313)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: structseq() takes at most 2 keyword arguments (10 given)

os.stat_result() accepts only two arguments: a tuple for indexable elements and 
a dict for non-indexable elements.

>>> os.stat_result((8630, 6, 6, 1, 0, 0, 0, 1602523313, 1602523313, 
>>> 1602523313), {'st_atime': 1602523313.282834, 'st_mtime': 1602523313.282834, 
>>> 'st_ctime': 1602523313.282834, 'st_atime_ns': 1602523313282834115, 
>>> 'st_mtime_ns': 1602523313282834115, 'st_ctime_ns': 1602523313282834115, 
>>> 'st_blksize': 4096, 'st_blocks': 0, 'st_rdev': 259})
os.stat_result(st_mode=8630, st_ino=6, st_dev=6, st_nlink=1, st_uid=0, 
st_gid=0, st_size=0, st_atime=1602523313, st_mtime=1602523313, 
st_ctime=1602523313)

But such form looks not very readable, because it lacks names for indexable 
elements.

To solve this we can use an angular form in the repr:



--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2019-05-06 Thread MICHAEL BLAHAY


MICHAEL BLAHAY  added the comment:

I have been advised to avoid enhancements like this one, so I am setting this 
back down. Also, this should be relabeled as easy(c).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2019-05-06 Thread MICHAEL BLAHAY


MICHAEL BLAHAY  added the comment:

I will work on this

--
nosy: +MICHAEL BLAHAY

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2018-01-29 Thread Raymond Hettinger

Change by Raymond Hettinger :


--
versions: +Python 3.8 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2016-10-03 Thread Mark Lawrence

Changes by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2016-10-03 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
stage:  -> patch review
versions: +Python 3.7 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2015-01-21 Thread lilydjwg

Changes by lilydjwg :


--
nosy: +lilydjwg

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2014-08-01 Thread Mark Lawrence

Mark Lawrence added the comment:

Could somebody pick this up please as it fixes #5907.

--
nosy: +BreamoreBoy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-11-07 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

IMHO '*' could be used as a separator, since relation between indexable fields 
and named, unindexable fields is similar to relation between 
positional-or-keyword parameters and keyword-only parameters.

$./python -c "import os; print(os.stat('LICENSE'))"
os.stat_result(st_mode=33188, st_ino=577299, st_dev=64512, st_nlink=1, 
st_uid=33616, st_gid=600, st_size=12749, st_atime=1382696747, 
st_mtime=1382361968, st_ctime=1382361968, *, st_atime=1382696747.0, 
st_mtime=1382361968.0, st_ctime=1382361968.0, st_atime_ns=13826967470, 
st_mtime_ns=13823619680, st_ctime_ns=13823619680, 
st_blksize=4096, st_blocks=32, st_rdev=0)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-11-07 Thread Sunny K

Sunny K added the comment:

The previous patch had a wrong mapping between keys and values. The 
current implementation of repr means that duplicated keys will be
present when invisible fields are included. See points 2 and 3 in
http://bugs.python.org/issue1820#msg202330 for more explanation.

I have sidestepped that issue by placing invisible fields under the dict 
argument. This also plays well with the current code in 
structseq_new and eval(repr(obj)) works.

The output with the patch is:

$./python -c "import os; print(os.stat('LICENSE'))"
os.stat_result(st_mode=33188, st_ino=577299, st_dev=64512, st_nlink=1, 
st_uid=33616, st_gid=600, st_size=12749, st_atime=1382696747, 
st_mtime=1382361968, st_ctime=1382361968,
dict={'st_atime':1382696747.0, 'st_mtime':1382361968.0,
'st_ctime':1382361968.0, 'st_atime_ns':13826967470, 
'st_mtime_ns':13823619680, 'st_ctime_ns':13823619680, 
'st_blksize':4096, 'st_blocks':32, 'st_rdev':0})

--
Added file: http://bugs.python.org/file32527/structseq_2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-11-07 Thread Sunny K

Changes by Sunny K :


Removed file: http://bugs.python.org/file32265/structseq.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-10-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Hmm, does anyone have an opinion for or against the proposed representation in 
Sunny's patch? 

Sunny, if you haven't done so, could you sign a contributor's agreement? 
http://www.python.org/psf/contrib/
Thanks!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-10-20 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-10-20 Thread Sunny K

Sunny K added the comment:

Added patch for 3.4.

The patch demarcates the output by adding a {...} around the dictionary 
portion. Please let me know if this is the right format or if not required at 
all. It is a simple change.

--
nosy: +sunfinite
Added file: http://bugs.python.org/file32265/structseq.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-07-12 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
versions: +Python 3.4 -Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-06-25 Thread Eric Snow

Changes by Eric Snow :


--
nosy: +eric.snow

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-05-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thanks for the patch. (Yes, I'm looking at this a bit late :-))

First, there seems to be a problem with the repr() of of.stat() results:

 ./python -c "import os; print(os.stat('LICENSE'))"
posix.stat_result(st_mode=33204, st_ino=6553619, st_dev=2053, st_nlink=1, 
st_uid=1000, st_gid=1000, st_size=15089, st_atime=1367693898, 
st_mtime=1365264866, st_ctime=1366481591, st_atime=1367693898.528636, 
st_mtime=1365264866.4163036, st_ctime=1366481591.9862735, 
st_atime_ns=1367693898528635928, st_mtime_ns=1365264866416303676, 
st_ctime_ns=1366481591986273627, st_blksize=4096, st_blocks=32, st_rdev=0)

As you see, fields such as "st_atime" are duplicated.

There are other issues with the patch:

* C variable declarations should always be at the beginning of blocks 
(otherwise it's not C89-compliant)

* C++-style comments (//) are forbidden

* I don't understand in which circumstances 
`Py_TYPE(obj)->tp_members[i-n_unnamed_fields].name` can be NULL

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2013-04-19 Thread Phil Connell

Changes by Phil Connell :


--
nosy: +pconnell

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-08-23 Thread moijes12

Changes by moijes12 :


--
nosy:  -moijes12

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-08-23 Thread moijes12

Changes by moijes12 :


--
nosy: +moijes12

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-07-16 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis :


--
nosy: +Arfrever

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-07-15 Thread David Lam

David Lam  added the comment:

hi hi,  found this bug after clicking the "Easy issues" link

i basically just took Ray's hint to look at the __reduce__ method, and applied 
it to the __repr__ method in this patch

also updated is the test_repr() unittest

--
keywords: +patch
nosy: +dlam
Added file: http://bugs.python.org/file26391/issue11698.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-03-09 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

+1. Also, the repr() should show the float values of st_mtime and friends, 
rather than truncated integers.

--
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-02-19 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +ezio.melotti

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-02-19 Thread Éric Araujo

Éric Araujo  added the comment:

You are!  See the devguide for more setup guidelines.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2012-02-19 Thread Berker Peksag

Berker Peksag  added the comment:

I'd like to work on this issue. I found the Objects/structseq.c [1] file. Am I 
on the right path?

Thanks!

[1] http://hg.python.org/cpython/file/5b4b70bd2b6f/Objects/structseq.c#l157

--
nosy: +berker.peksag

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2011-07-13 Thread Éric Araujo

Changes by Éric Araujo :


--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11698] Improve repr for structseq objects to show named, but unindexed fields

2011-03-27 Thread Raymond Hettinger

New submission from Raymond Hettinger :

The current __repr__ for structseq only shows the name/value pairs for the 
positional part and it ignores the other named fields.

For example, os.stat(somefile) returns:
posix.stat_result(st_mode=33277, st_ino=8468407, st_dev=234881026, st_nlink=1, 
st_uid=0, st_gid=80, st_size=25424, st_atime=1301263901, st_mtime=1298229258, 
st_ctime=1298283922)

but it doesn't show the other named fields and their values:
{'st_ctime': 1298283922.0, 'st_rdev': 0, 'st_mtime': 1298229258.0, 'st_blocks': 
56, 'st_flags': 0, 'st_gen': 0, 'st_atime': 1301263901.0, 'st_blksize': 4096, 
'st_birthtime': 1298229258.0}

The __reduce__ method for structseq returns both the tuple portion and the 
dictionary portion.  The latter needs to be added to the repr so that 
information doesn't get hidden from the user.

--
components: Interpreter Core
keywords: easy
messages: 132372
nosy: rhettinger
priority: low
severity: normal
status: open
title: Improve repr for structseq objects to show named, but unindexed fields
type: feature request
versions: Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com