Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15622] struct module 'c' specifier does not follow PEP-3118

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 11, 2012, 1:06 AM

Post #1 of 13 (146 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118

Changes by Stefan Krah <stefan-usenet [at] bytereef>:


----------
title: memoryview.to_list() incorrect for 'c' format -> struct module 'c' specifier does not follow PEP-3118

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 2:18 AM

Post #2 of 13 (145 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Martin v. Löwis added the comment:

No, I haven't rejected the format codes. What I did ask to revert is that 'u' in the array module denotes Py_UCS4, I requested that it should continue to be compatible with 3.2. I didn't have an opinion on memoryview at all then.

It's unfortunate that PEP 3118 deviates from the struct module, however, memoryview is based onthe buffer interface,and its formatcodes ought to conform to the PEP, not to the struct module (IMO).

It's easy to see that it *doesn't* follow the struct syntax, as it is possjible to create memoryview objects with other format codes in 3.3.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 2:44 AM

Post #3 of 13 (138 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Stefan Krah added the comment:

Martin v. L??wis <report [at] bugs> wrote:
> It's unfortunate that PEP 3118 deviates from the struct module, however,
> memoryview is based onthe buffer interface,and its formatcodes ought to
> conform to the PEP, not to the struct module (IMO).

The struct module itself should conform to PEP-3118, see #3132.

I think the struct module should be updated first. The proliferation of
subtly different format codes is not manageable. For example, if you use
NumPy, there are already differences between NumPy syntax and struct syntax.

Also, one should always be able to unpack the tobytes() representation
using the struct module and get the same result as from flatten(tolist()).

> It's easy to see that it *doesn't* follow the struct syntax, as it is
> possjible to create memoryview objects with other format codes in 3.3.

memoryview has *always* allowed arbitrary format strings during construction.
In 3.3, it keeps this property for backwards compatibility.

It does follow struct syntax whenever it *uses* one of the format codes,
like in tolist().

----------
title: memoryview.to_list() incorrect for 'c' format -> struct module 'c' specifier does not follow PEP-3118

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 3:00 AM

Post #4 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Changes by Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA [at] GMail>:


----------
nosy: +Arfrever

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 3:08 AM

Post #5 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Changes by Stefan Krah <stefan-usenet [at] bytereef>:


----------
dependencies: +implement PEP 3118 struct changes
title: memoryview.to_list() incorrect for 'c' format -> struct module 'c' specifier does not follow PEP-3118

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 3:35 AM

Post #6 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Martin v. Löwis added the comment:

Do you agree or not agree that memoryview.tolist should return a list of str objects for the c code?

If you agree, can you please change the title back?

If you disagree, please explain why, change the title back, and close the issue as rejected.

If you agree, but think that struct should be changed first, create a new issue for the struct change, make that a dependency of this issue, and change the title back.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 7:20 AM

Post #7 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Nick Coghlan added the comment:

Whatever the struct module produces for a format code is the same thing that memoryview.to_list() should produce.

PEP 3118 contains way too many errors (as has been found out the hard way) to be considered a normative document.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 7:40 AM

Post #8 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Nick Coghlan added the comment:

<Closing with rationale, as Martin requested>

The struct module documentation takes precedence over PEP 3118 when it comes to pre-existing format codes, as changing struct is not feasible due to backwards compatibility concerns, and we don't want two conflicting notations for binary format descriptions. PEP 3118 was intended only to define *additional* format characters, which may or may not yet be understood by the struct module.

As 'c' is defined by the struct module as returning a bytes object of length one, this is the same interpretation used by memoryview.

Thus the current behaviour of both memoryview and struct are considered correct, while it is PEP 3118 that is incorrect in this case: the 'c' entry should not have been in the table, as 'c' was already defined at least as long ago as 1.5.2 (returning an 8-bit string, which then became a bytes object in 3.x).

The PEP was also written in a 2.x context (note the mention of "2.5" above the table of new format codes), where the idea of providing a separate code that implicitly performed x.decode("latin-1") to produce a unicode object instead of an 8-bit string object wouldn't necessarily come up.

----------
dependencies: -implement PEP 3118 struct changes
resolution: -> invalid
stage: -> committed/rejected

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 8:03 AM

Post #9 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Nick Coghlan added the comment:

However, based on this issue, I have added some comments to #3132 (I think PEP 3118's simplistic approach to embedded text data is broken and a bad idea)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 8:03 AM

Post #10 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Changes by Nick Coghlan <ncoghlan [at] gmail>:


----------
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 8:06 AM

Post #11 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Chris Jerdonek added the comment:

> <Closing with rationale, as Martin requested>

Status was still open. Was that a tracker bug?

----------
nosy: +cjerdonek

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 8:21 AM

Post #12 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Nick Coghlan added the comment:

Pretty sure it was just an error on my part.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2012, 10:09 AM

Post #13 of 13 (139 views)
Permalink
[issue15622] struct module 'c' specifier does not follow PEP-3118 [In reply to]

Martin v. Löwis added the comment:

Nick: that's a reasonable view, thanks - in particular the point that PEP 3118 should not be considered normative.

I still think that the c code in struct is fairly redundant (with B) as it stands, so I think it should get deprecated and removed - but that's a different issue.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.