[issue29903] struct.Struct Addition

2017-04-21 Thread STINNER Victor

STINNER Victor added the comment:

I dislike this feature. I reject it: Serhiy, Raymond and me dislike it.

I never needed this feature and a correct implementation can be very complex if 
you have to take care of endian, alignement, etc. It's trivial to implement you 
own add using the format attribute if you want the simple implementation 
format1+format2.

--
nosy: +haypo
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Martin Panter

Martin Panter added the comment:

For the native alignment case (prefix code @), perhaps you can already use the 
“ctypes” module, which supports structures with more complicated embedded 
fields.

For the the unaligned modes (prefixes =, <, > and !), I am a little 
sympathetic. In the past, I wanted to make various structures that extended 
from a common base structure:

HSF_VOL_DESC = Struct("< B 5s B")

# Python 3's "Struct.format" is a byte string!
NSR_DESC = Struct(HSF_VOL_DESC.format.decode() + "B")

But I think if Issue 21071 was fixed (change Struct.format to text string, or 
perhaps add a new attribute), I would be happy enough writing

NSR_DESC = Struct(HSF_VOL_DESC.format_str + "B")

Transforming Aviv’s examples:

s3 = Struct(s1.format_str + s2.format_str[1:])
s3 = Struct(s1.format_str + "B")  # if s2 is not needed on its own
ver2 = Struct(ver1.format_str + "I")
version_a = Struct(start.format_str + union_b.format_str[1:])

--
nosy: +martin.panter

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Aviv Palivoda

Aviv Palivoda added the comment:

I have two use cases for this feature:
1.

struct a {
int a;
#ifdef VER2
unsigned int b;
#endif
}

Now I may do:
>>> ver1 = Struct("i")
>>> ver2 = ver1 + Struct("I")

2.

struct a {
int a;
union inner {
int b;
unsigned int c;
} u;
}

As you can see with this feature I may do:
>>> start = Struct("i")
>>> union_b = Struct("i")
>>> union_c = Struct("I")
>>> version_a = start + union_b
>>> version_b = start + union_c

If you have a big struct with many options in the union this save's copying the 
initial format.

> As for the concrete implementation, it looks to me that Struct('2L') + 
> Struct('25B') results to Struct('2L5B').

I will fix the case when there is no format provided.

--

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I concur with Serhiy that this proposal is likely to cause more problems than 
it solves.

--
nosy: +rhettinger

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

What is the purpose of this feature? Note that the layout of the structure 
consisting of two structures is not the same as the layout of the structure 
consisting of the same fields as separate structures.

struct {
struct {
char a;
short b;
} s1;
struct {
char c;
int d;
} s2;
}

and

struct {
char a;
short b;
char c;
int d;
}

can have different sizes and offsets of fields.

As for the concrete implementation, it looks to me that Struct('2L') + 
Struct('25B') results to Struct('2L5B').

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Aviv Palivoda

Changes by Aviv Palivoda :


--
pull_requests: +723

___
Python tracker 

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



[issue29903] struct.Struct Addition

2017-03-25 Thread Aviv Palivoda

New submission from Aviv Palivoda:

I would like to suggest that the struct.Struct class will support addition. For 
example you will be able to do:

>>> s1 = Struct(">L")
>>> s2 = Struct(">B")
>>> s3 = s1 + s2
>>> s3.format
b">LB"

--
components: Extension Modules
messages: 290486
nosy: mark.dickinson, meador.inge, palaviv
priority: normal
severity: normal
status: open
title: struct.Struct Addition
type: enhancement
versions: Python 3.7

___
Python tracker 

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