Skip to content

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

❌ Patch coverage is 97.88360% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.92%. Comparing base (c708b6a) to head (bad3e82).

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

❌ Your patch check has failed because the patch coverage (97.88%) 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.90%   95.92%   +0.02%     
==========================================
  Files         177      177              
  Lines       19368    19553     +185     
==========================================
+ Hits        18574    18756     +182     
- Misses        794      797       +3     
Files with missing lines Coverage Δ
pylint/checkers/format.py 97.52% <97.88%> (+0.52%) ⬆️
🚀 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

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the scientific-notation-formatting branch from dc7592d to bad3e82 Compare September 13, 2025 13:32
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:
    '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/9f8f7d2fde9b0ca5e5e961a3ebaa9bc5b48f5090/homeassistant/util/location.py#L26
  2. 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/9f8f7d2fde9b0ca5e5e961a3ebaa9bc5b48f5090/homeassistant/util/unit_conversion.py#L734
  3. 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/9f8f7d2fde9b0ca5e5e961a3ebaa9bc5b48f5090/homeassistant/components/esphome/light.py#L244

Effect on sentry:
The following messages are now emitted:

  1. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L123
  2. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L129
  3. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L130
  4. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L145
  5. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L151
  6. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L152
  7. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L170
  8. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L176
  9. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/replay_examples.py#L177
  10. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L53
  11. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L54
  12. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L55
  13. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L56
  14. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L57
  15. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L58
  16. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L59
  17. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L60
  18. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L61
  19. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L62
  20. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L63
  21. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L64
  22. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L65
  23. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L66
  24. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L67
  25. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L68
  26. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L69
  27. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L70
  28. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L71
  29. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L72
  30. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L73
  31. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L74
  32. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L75
  33. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/apidocs/examples/issue_examples.py#L76
  34. bad-float-notation:
    '0.00' is smaller than 1e-6, and it should be written as '0.0' instead
    https://github.com/getsentry/sentry/blob/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/options/defaults.py#L1287
  35. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/testutils/helpers/notifications.py#L289
  36. 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/93c93df08d5756fc48efd424151763cfb4cbd863/src/sentry/web/frontend/debug/mail.py#L198

This comment was generated for commit bad3e82

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