Message404624
Thinking a little more about this, maybe a different solution would be to have default values be installed at the class level by default without being overwritten in the init, as is the case today. default_factory should keep being set in the init as is the case today.
With this approach:
@dataclass
class Foo:
bar = field(default=4)
# assigns 4 to Foo.bar but not to foo.bar (bonus: __init__ will be faster)
bar = field(default=some_descriptor)
# assigns some_descriptor to Foo.bar, so Foo().bar does a __get__ on the descriptor
bar = field(default_factory=SomeDescriptor)
# assigns a new SomeDescriptor instance to every instance of Foo
bar = field(default_factory=lambda: some_descriptor)
# assigns the same descriptor object to every instance of Foo
I don't think this change would break a lot of existing code as the attribute overwrite that happens at the instance level in the __init__ is essentially an implementation detail. It also seems this would solve the current problem and allow for a cleaner way to assign a descriptor object as a default value. Am I not seeing some obvious problem here ? |
|
Date |
User |
Action |
Args |
2021-10-21 17:09:20 | Thomas701 | set | recipients:
+ Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen |
2021-10-21 17:09:20 | Thomas701 | set | messageid: <1634836160.54.0.88874472772.issue39247@roundup.psfhosted.org> |
2021-10-21 17:09:20 | Thomas701 | link | issue39247 messages |
2021-10-21 17:09:20 | Thomas701 | create | |
|