float missing .0
in the pop-up window
#4030
Replies: 5 comments
-
@erictraut, I thought I remembered seeing a comment from you on an old issue saying that this is by design, but I can't find it. |
Beta Was this translation helpful? Give feedback.
-
This is purely a display issue, so it has no impact on type analysis, so the pylance team should decide how best to display numbers in expressions. Currently, the expression printing logic prints the value of the numeric literal, and it uses standard numeric formatting. That means We could print the exact text that was found in the source file rather than computing its value. I see pros and cons to both approaches. I think the options are:
Keep in mind that the expression printing logic is also used for logs and some error messages, so all of those would be affected by a change here. |
Beta Was this translation helpful? Give feedback.
-
The reason I think this is a problem from a user perspective is that it sometimes makes me think I accidentally declared the default value as int instead of float (because there is no way to distinguish between the two). So when I run into this, I usually have to go to the definition to make sure it is indeed float. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
I just ran into a similar issue in #6608 (comment), where long ints such as EDIT: oh, it looks like this isn't open source? :( @erictraut if you point me towards the files that should get changed, I can file a PR that does the basic changes here. I will start with the simple solution that you suggest, that only affects the printing code:
I don't see how this would be a regression in any case, and I bet it solves 80% of the need without resorting to needing to find the source text. |
Beta Was this translation helpful? Give feedback.
-
Environment data
Code Snippet
Repro Steps
Expected behavior
It should show
(function) def f(x: float = 1.0) -> float
, which respects what I wrote in the function.Actual behavior
The
.0
is missing. It only shows(function) def f(x: float = 1) -> float
.Notes
This problem exists for all floating point numbers ending in ".0" (e.g.
1.0
,2.
, ...).Beta Was this translation helpful? Give feedback.
All reactions