This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Thomas701
Recipients Michael Robellard, Thomas701, UnHumbleBen, eric.smith, iivanyuk, juanpa.arrivillaga
Date 2021-10-21.17:27:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634837256.91.0.879075483348.issue39247@roundup.psfhosted.org>
In-reply-to
Content
Scratch that last one, it leads to problem when mixing descriptors with actual default values:

@dataclass
class Foo:
    bar = field(default=some_descriptor)
    # technically this is a descriptor field without a default value or at the very least, the dataclass constructor can't know because it doesn't know what field, if any, this delegates to. This means this will show up as optional in the __init__ signature but it might not be.

    bar = field(default=some_descriptor, default_factory=lambda:4)
    # this could be a solve for the above problem. The dc constructor would install the constructor at the class level and assign 4 to the instance attribute in the __init__. Still doesn't tell the dc constructor if a field is optional or not when it's default value is a descriptor and no default_factory is passed. And it feels a lot more like hack than anything else.


So ignore my previous message. I'm still 100% behind the "descriptor" arg in the field constructor, though :)

PS: Sorry for the noise, I just stumbled onto this problem for the nth-times and I can't get my brain to shut off.
History
Date User Action Args
2021-10-21 17:27:36Thomas701setrecipients: + Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen
2021-10-21 17:27:36Thomas701setmessageid: <1634837256.91.0.879075483348.issue39247@roundup.psfhosted.org>
2021-10-21 17:27:36Thomas701linkissue39247 messages
2021-10-21 17:27:36Thomas701create