[
https://issues.apache.org/jira/browse/THRIFT-2616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sylwester Lachiewicz resolved THRIFT-2616.
------------------------------------------
Fix Version/s: 0.12.0
Resolution: Fixed
The Python generator renders whole-number double defaults as float literals:
[t_py_generator.cc|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_py_generator.cc]
{{render_const_value}} TYPE_DOUBLE branch emits {{float(N)}} when the constant
was written as an integer, so the value keeps its double type. Present since
0.12.0. Resolving as Fixed.
> Double constant that happens to be a whole number (integer) gets converted to
> int in generated code
> ---------------------------------------------------------------------------------------------------
>
> Key: THRIFT-2616
> URL: https://issues.apache.org/jira/browse/THRIFT-2616
> Project: Thrift
> Issue Type: Bug
> Components: Python - Compiler
> Affects Versions: 0.9.1
> Reporter: Morten Lied Johansen
> Priority: Minor
> Fix For: 0.12.0
>
>
> In Python, the value you use to initialize a constant determines the type it
> has. When a constant is declared as a double, it should be a double in the
> generated code, even if it happens to be possible to represent it as an int.
> Example:
> {code}
> const double RADIUS = 15.0;
> {code}
> will generate the following Python:
> {code}
> RADIUS = 15
> {code}
> it should have generated this:
> {code}
> RADIUS = 15.0
> {code}
> Most of the time this is not going to be a problem, but every now and then
> you get some wrong results when doing math with different types.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)