[issue45531] field "mro" behaves strangely in dataclass

2021-10-19 Thread Finite State Machine


New submission from Finite State Machine :

The following Python script:

from dataclasses import dataclass

@dataclass
class A:
mro: object
x: object

Results in the following unexpected exception:

Traceback (most recent call last):
  File "/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", 
line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
  File "/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", 
line 86, in _run_code
exec(code, run_globals)
  File "/Users/dsuffling/names/junk.py", line 6, in 
class A:
  File 
"/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/dataclasses.py", line 
1178, in dataclass
return wrap(cls)
  File 
"/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/dataclasses.py", line 
1169, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
  File 
"/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/dataclasses.py", line 
1019, in _process_class
_init_fn(all_init_fields,
  File 
"/Users/dsuffling/.pyenv/versions/3.10.0/lib/python3.10/dataclasses.py", line 
540, in _init_fn
raise TypeError(f'non-default argument {f.name!r} '
TypeError: non-default argument 'x' follows default argument


The name of the first attribute ('mro') is critical; without it the problem 
does not occur.

It appears that 'mro' is somehow interacting with the 'mro' attribute of the 
'type' object.

This issue has been verified to occur with CPython 3.10.0.

--
components: Library (Lib)
messages: 404378
nosy: finite-state-machine
priority: normal
severity: normal
status: open
title: field "mro" behaves strangely in dataclass
type: behavior
versions: Python 3.10

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



[issue45531] field "mro" behaves strangely in dataclass

2021-10-20 Thread Finite State Machine


Finite State Machine  added the comment:

For what it's worth, I think a sensible exception message solves this problem. 
While it would be nice to be able to use a field called 'mro', that's an 
enhancement; the misleading exception message is a bug.

--

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



[issue43532] Add keyword-only fields to dataclasses

2021-10-21 Thread Finite State Machine


Finite State Machine  added the comment:

I doubt it's worth opening a separate issue for this, so I'll mention it here:

In the documentation 
(https://docs.python.org/3.10/library/dataclasses.html#dataclasses.KW_ONLY) 
nothing documents KW_ONLY as being new in Python 3.10.

--
nosy: +finite-state-machine

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