ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Methods and properties with type annotations should be ignored. #6

Closed ericvsmith closed 7 years ago

ericvsmith commented 7 years ago

In this python-ideas post, Nick Coghlan says:

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.