[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Darrick Yee


Darrick Yee  added the comment:

Yes, that makes sense. Thank you!

On Wed, May 27, 2020, 1:40 PM Eric V. Smith  wrote:

>
> Eric V. Smith  added the comment:
>
> No problem!
>
> It can't reorder fields, because you might not be passing them by name.
> There's some discussion about requiring keyword-only parameters, in which
> case what you're doing would work (as long as they were keyword-only
> params).
>
> --
> resolution:  -> not a bug
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

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



[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Eric V. Smith


Eric V. Smith  added the comment:

No problem!

It can't reorder fields, because you might not be passing them by name. There's 
some discussion about requiring keyword-only parameters, in which case what 
you're doing would work (as long as they were keyword-only params).

--
resolution:  -> not a bug

___
Python tracker 

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



[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Darrick Yee


Darrick Yee  added the comment:

TypeError: non-default argument 'field1' follows default argument

You are right.  For some reason I believed it would automatically gather the 
required fields first when creating the new class' signature.

--

___
Python tracker 

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



[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Darrick Yee


Change by Darrick Yee :


--
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



[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Eric V. Smith


Eric V. Smith  added the comment:

Isn't this error that you're providing a field without a default value after 
one with a default value?

What's the exception look like?

--
nosy: +eric.smith

___
Python tracker 

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



[issue40796] dataclasses.make_dataclass: Exception when called with different field orders

2020-05-27 Thread Darrick Yee


New submission from Darrick Yee :

https://docs.python.org/3/library/dataclasses.html#module-dataclasses

`make_dataclass` takes a `field` parameter, which is an iterable whose entries 
may be tuples of `(name, type)` or `(name, type, dataclasses.Field)`.  However, 
an exception is thrown if such tuples are provided in a particular order.  
Example:


from dataclasses import field, make_dataclass

fieldspec1 = ('field1', str)
fieldspec2 = ('field2', str, field(default='Hello'))

MyDc1 = make_dataclass('MyDc1', [fieldspec1, fieldspec2]) # Ok
MyDc2 = make_dataclass('MyDc2', [fieldspec2, fieldspec1]) # TypeError

I am guessing this is not intentional...

--
messages: 370112
nosy: Darrick Yee
priority: normal
severity: normal
status: open
title: dataclasses.make_dataclass: Exception when called with different field 
orders
type: behavior
versions: Python 3.7, Python 3.8

___
Python tracker 

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