Skip to content

[format check] Misleading scientific, engineering, or underscore grouping notations in float #10425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas commented Jun 12, 2025

Type of Changes

Type
✨ New feature

Description

A little experiment to gather feedback with primers and reviews (still a draft).

The idea is to enforce normalized ways to write number above a threshold or close to 0 in absolute value:

  • Engineering notation (float)
  • Scientific notation (float)
  • Pep515 notation with underscore separated by pack of 3 digit (float or int)

Another idea could be to warn to use python's Decimal for number with more than 15 digits of precision, not sure if it should be the same checker though. We could also set/enforce a default precision for a project.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.0 milestone Jun 12, 2025
@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Jun 12, 2025
Comment on lines +463 to +529
if string.endswith("l"):
self.add_message("lowercase-l-suffix", line=line_num)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never raised anywhere, the definition of the message cannot be found, not sure what it's about.

Copy link

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 97.35450% with 5 lines in your changes missing coverage. Please review.

Project coverage is 95.90%. Comparing base (f5aa766) to head (dc7592d).

Files with missing lines Patch % Lines
pylint/checkers/format.py 97.35% 5 Missing ⚠️

❌ Your patch check has failed because the patch coverage (97.35%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10425      +/-   ##
==========================================
+ Coverage   95.88%   95.90%   +0.01%     
==========================================
  Files         176      176              
  Lines       19140    19325     +185     
==========================================
+ Hits        18352    18533     +181     
- Misses        788      792       +4     
Files with missing lines Coverage Δ
pylint/checkers/format.py 97.08% <97.35%> (+0.47%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from fdf5bc1 to 18b00a7 Compare June 13, 2025 19:11
@Pierre-Sassoulas Pierre-Sassoulas changed the title [format] Add a check for standard scientific notation [format check] Misleading scientific notations and use of underscore grouping in float Jun 13, 2025
@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as draft June 14, 2025 18:53
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems useful, but would probably make it an extension? Or perhaps, first have it as an extension to get feedback?

@mbyrnepr2
Copy link
Member

+1 for the idea

@Pierre-Sassoulas Pierre-Sassoulas changed the title [format check] Misleading scientific notations and use of underscore grouping in float [format check] Misleading scientific, engineering or underscore grouping notations in float Jun 17, 2025
@Pierre-Sassoulas Pierre-Sassoulas changed the title [format check] Misleading scientific, engineering or underscore grouping notations in float [format check] Misleading scientific, engineering, or underscore grouping notations in float Jun 17, 2025
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from f3ff9d4 to 1db9508 Compare June 17, 2025 21:35
Comment on lines 515 to 524
"x" not in string # not a hexadecimal
and "o" not in string # not an octal
and "j" not in string # not a complex
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 515 is talking about separating word in hexadecimal, might want to do something about it... later.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from 1db9508 to 77a3d6b Compare June 18, 2025 12:29

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from cbe8b6a to 2886dc7 Compare June 21, 2025 09:12

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from 8ba51e0 to 35898de Compare June 21, 2025 19:41

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from afc04e3 to dc7592d Compare June 22, 2025 20:57
Copy link
Contributor

🤖 Effect of this PR on checked open source code: 🤖

Effect on home-assistant:
The following messages are now emitted:

  1. bad-float-notation:
    '1000000.0' is bigger than 1e6, and it should be written as '1_000_000.0' or '1e6' instead
    https://github.com/home-assistant/core/blob/7442f7af28d28a2f6e5417f4cb45e08476be63ac/homeassistant/components/esphome/light.py#L244
  2. bad-float-notation:
    '6356752.314245' is bigger than 1e6, and it should be written as '6.356752314245e6' or '6_356_752.314245' instead
    https://github.com/home-assistant/core/blob/7442f7af28d28a2f6e5417f4cb45e08476be63ac/homeassistant/util/location.py#L26

Effect on sentry:
The following messages are now emitted:

  1. bad-float-notation:
    '1541455200.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (320 * 3600 * 24) + (22 * 3600)' or '1.5414552e9' or '1_541_455_200.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L53
  2. bad-float-notation:
    '1541458800.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (320 * 3600 * 24) + (23 * 3600)' or '1.5414588e9' or '1_541_458_800.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L54
  3. bad-float-notation:
    '1541462400.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24)' or '1.5414624e9' or '1_541_462_400.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L55
  4. bad-float-notation:
    '1541466000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (1 * 3600)' or '1.541466e9' or '1_541_466_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L56
  5. bad-float-notation:
    '1541469600.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (2 * 3600)' or '1.5414696e9' or '1_541_469_600.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L57
  6. bad-float-notation:
    '1541473200.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (3 * 3600)' or '1.5414732e9' or '1_541_473_200.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L58
  7. bad-float-notation:
    '1541476800.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (4 * 3600)' or '1.5414768e9' or '1_541_476_800.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L59
  8. bad-float-notation:
    '1541480400.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (5 * 3600)' or '1.5414804e9' or '1_541_480_400.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L60
  9. bad-float-notation:
    '1541484000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (6 * 3600)' or '1.541484e9' or '1_541_484_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L61
  10. bad-float-notation:
    '1541487600.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (7 * 3600)' or '1.5414876e9' or '1_541_487_600.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L62
  11. bad-float-notation:
    '1541491200.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (8 * 3600)' or '1.5414912e9' or '1_541_491_200.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L63
  12. bad-float-notation:
    '1541494800.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (9 * 3600)' or '1.5414948e9' or '1_541_494_800.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L64
  13. bad-float-notation:
    '1541498400.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (10 * 3600)' or '1.5414984e9' or '1_541_498_400.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L65
  14. bad-float-notation:
    '1541502000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (11 * 3600)' or '1.541502e9' or '1_541_502_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L66
  15. bad-float-notation:
    '1541505600.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (12 * 3600)' or '1.5415056e9' or '1_541_505_600.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L67
  16. bad-float-notation:
    '1541509200.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (13 * 3600)' or '1.5415092e9' or '1_541_509_200.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L68
  17. bad-float-notation:
    '1541512800.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (14 * 3600)' or '1.5415128e9' or '1_541_512_800.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L69
  18. bad-float-notation:
    '1541516400.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (15 * 3600)' or '1.5415164e9' or '1_541_516_400.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L70
  19. bad-float-notation:
    '1541520000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (16 * 3600)' or '1.54152e9' or '1_541_520_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L71
  20. bad-float-notation:
    '1541523600.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (17 * 3600)' or '1.5415236e9' or '1_541_523_600.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L72
  21. bad-float-notation:
    '1541527200.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (18 * 3600)' or '1.5415272e9' or '1_541_527_200.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L73
  22. bad-float-notation:
    '1541530800.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (19 * 3600)' or '1.5415308e9' or '1_541_530_800.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L74
  23. bad-float-notation:
    '1541534400.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (20 * 3600)' or '1.5415344e9' or '1_541_534_400.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L75
  24. bad-float-notation:
    '1541538000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 48) + (321 * 3600 * 24) + (21 * 3600)' or '1.541538e9' or '1_541_538_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/issue_examples.py#L76
  25. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L123
  26. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L129
  27. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L130
  28. bad-float-notation:
    '1665063926.125' is bigger than 1e6, and it should be written as '1.665063926125e9' or '1_665_063_926.125' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L145
  29. bad-float-notation:
    '1665063926.125' is bigger than 1e6, and it should be written as '1.665063926125e9' or '1_665_063_926.125' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L151
  30. bad-float-notation:
    '1665063926.833' is bigger than 1e6, and it should be written as '1.665063926833e9' or '1_665_063_926.833' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L152
  31. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L170
  32. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L176
  33. bad-float-notation:
    '1658770772.902' is bigger than 1e6, and it should be written as '1.658770772902e9' or '1_658_770_772.902' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/apidocs/examples/replay_examples.py#L177
  34. bad-float-notation:
    '172422171096.56' is bigger than 1e6, and it should be written as '1.7242217109656e11' or '172.42217109656e9' or '172_422_171_096.56' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/testutils/helpers/notifications.py#L289
  35. bad-float-notation:
    '1504656000.0' is bigger than 1e6, and it should be written as '(3600 * 24 * 365 * 47) + (260 * 3600 * 24)' or '1.504656e9' or '1_504_656_000.0' instead
    https://github.com/getsentry/sentry/blob/0da785052b486eb791022727af5805a291d059a4/src/sentry/web/frontend/debug/mail.py#L198

This comment was generated for commit dc7592d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants