[issue45531] field "mro" behaves strangely in dataclass

2021-10-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Would not be more correct to look at cls.__dict__[fieldname]? BTW, mro() cannot be builtin, because you should be able to override it in some classes. -- ___ Python tracker

[issue45531] field "mro" behaves strangely in dataclass

2021-10-22 Thread Eric V. Smith
Eric V. Smith added the comment: The problem is that dataclasses is looking for a default value for a field by looking at getattr(cls, fieldname), which returns a value when fieldname is "mro". I think the best thing to do, at least for now, is prohibit a field named "mro". Ultimately I'd

[issue45531] field "mro" behaves strangely in dataclass

2021-10-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Where does dataclasses call mro()? -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue45531] field "mro" behaves strangely in dataclass

2021-10-22 Thread Éric Araujo
Éric Araujo added the comment: If dataclasses wanted to allow fields named `mro`, it could replace its call to `cls.mro()` with `type.mro(cls)`. But I don’t know if there is a strong use case for such a field. -- nosy: +eric.araujo ___ Python

[issue45531] field "mro" behaves strangely in dataclass

2021-10-20 Thread Eric V. Smith
Eric V. Smith added the comment: I think the only other thing that could be done is to have a special test for "default is type.mro", and if so, don't assume it's a default value. Which means that you could never actually use: @dataclass class A: mro: object = type.mro But it's probably

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

[issue45531] field "mro" behaves strangely in dataclass

2021-10-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: In Enum it is just implicitly forbidden: >>> from enum import * >>> class A(Enum): ... mro = 1 ... x = 2 ... Traceback (most recent call last): File "", line 1, in File "/home/serhiy/py/cpython/Lib/enum.py", line 430, in __new__ raise

[issue45531] field "mro" behaves strangely in dataclass

2021-10-19 Thread Eric V. Smith
Eric V. Smith added the comment: I agree on your analysis. You'll get the same error on any name that type defines (like __class__), but "mro" looks like the only one without dunders. I'm not sure the best way to fix this. I'll give it some thought. Another problem is that assigning a

[issue45531] field "mro" behaves strangely in dataclass

2021-10-19 Thread Eric V. Smith
Change by Eric V. Smith : -- assignee: -> eric.smith nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list

[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