3 ms·
In Python we sometimes differentiate the different meanings like "whatever", "default" or "not set yet" by defining a singleton object and comparing by identity
by kissgyorgy 7y ago
In Python we sometimes differentiate the different meanings like "whatever", "default" or "not set yet" by defining a singleton object and comparing by identity, because None would be acceptable value and we need to differentiate the meaning. Examples:
https://github.com/marshmallow-code/marshmallow/blob/c1506cc48edf927fa7074f237f951a11f04df7c0/src/marshmallow/utils.py#L35-L38 https://github.com/marshmallow-code/marshmallow/blob/c1506cc...
https://github.com/python-attrs/attrs/blob/eda9f2de6f7026039c3eee80297f0c95382d51d8/src/attr/_make.py#L67-L70 https://github.com/python-attrs/attrs/blob/eda9f2de6f7026039...