That said, even with this model, the base case of "fields with an
immutable or shared default" could potentially be simplified to:
from autoclass import data_record
@data_record
class Point3D:
x: int = 0
y: int = 0
z: int = 0
However, the potentially surprising behaviour there is that to
implement it, the decorator not only has to special case the output of
"field()" calls, but also has to special case any object that
implements the descriptor protocol to avoid getting confused by normal
method and property definitions.
I don't believe the last sentence is true, because __annotations__ will not contain entries for properties or methods with type annotations.
This issue is to remind me to add test cases for this.
In this python-ideas post, Nick Coghlan says:
I don't believe the last sentence is true, because
__annotations__
will not contain entries for properties or methods with type annotations.This issue is to remind me to add test cases for this.