-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
I had a look around but couldn't find an existing issue. There is some strange rounding with float fields when the value is accessed on an instance vs encoded:
>>> import proto
...
... class Animal(proto.Message):
... size = proto.Field(proto.FLOAT, number=1)
...
>>> a = Animal(size=0.95)
>>> a
size: 0.95
>>> a.size
0.949999988079071Why is a.size significantly different from the value I provided? Also the textproto produced by stringifying and the value produced by to_dict() are correct:
>>> Animal.to_dict(a)
{'size': 0.95}
>>> Animal.to_dict(a)["size"] == a.size
FalseEnvironment details
- Programming language: Python 3.13
- OS: Linux
- Language runtime version: 3.13
- Package version:
proto-plus==1.25.0
Steps to reproduce
>>> import proto
...
... class Animal(proto.Message):
... size = proto.Field(proto.FLOAT, number=1)
...
>>> Animal(size=0.95)
size: 0.95
>>> Animal(size=0.95).size
0.949999988079071Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.