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 xtreak
Recipients corona10, eric.smith, serhiy.storchaka, xtreak, yselivanov
Date 2018-07-16.05:53:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1531720433.14.0.56676864532.issue34122@psf.upfronthosting.co.za>
In-reply-to
Content
I think there is some note about this on the doc as below : 

https://docs.python.org/3/library/dataclasses.html#dataclasses.field . Relevant commit : 98d50cb8f57eb227c373cb94b8680b12ec8aade5

If the default value of a field is specified by a call to field(), then the class attribute for this field will be replaced by the specified default value. If no default is provided, then the class attribute will be deleted. The intent is that after the dataclass() decorator runs, the class attributes will all contain the default values for the fields, just as if the default value itself were specified.

Using a default value returns the parameter in the inspect module as below : 


➜  cpython git:(master) ✗ cat foo.py
import inspect
from dataclasses import *
import enum

@dataclass
class SimpleDataObject(object):
    field_a: int = field(default=10)
    field_b: str = "asdad"

print([a[0] for a in inspect.getmembers(SimpleDataObject)])
➜  cpython git:(master) ✗ ./python foo.py
['__annotations__', '__class__', '__dataclass_fields__', '__dataclass_params__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'field_a', 'field_b']


I think this is an intended behavior as above and a test case could be added or docs could be improved about this with the inspect example?

Thanks
History
Date User Action Args
2018-07-16 05:53:53xtreaksetrecipients: + xtreak, eric.smith, serhiy.storchaka, yselivanov, corona10
2018-07-16 05:53:53xtreaksetmessageid: <1531720433.14.0.56676864532.issue34122@psf.upfronthosting.co.za>
2018-07-16 05:53:53xtreaklinkissue34122 messages
2018-07-16 05:53:52xtreakcreate