Skip to content

WPS303: Allow underscore with 3 digits on the right#3128

Merged
sobolevn merged 9 commits intowemake-services:masterfrom
mmmylnikov:issue-3120
Dec 13, 2024
Merged

WPS303: Allow underscore with 3 digits on the right#3128
sobolevn merged 9 commits intowemake-services:masterfrom
mmmylnikov:issue-3120

Conversation

@mmmylnikov
Copy link
Copy Markdown
Contributor

Checklist

  • [+] I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • [+] I have created at least one test case for the changes I have made
  • [+] I have updated the documentation for the changes I have made
  • [+] I have added my changes to the CHANGELOG.md

Related issues

This is my first pull request to this project, so please bear with me if I made any mistakes. Any comments or suggestions are welcome.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3d0b976) to head (6942545).
Report is 183 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3128   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          118       118           
  Lines         5788      5803   +15     
  Branches       801       804    +3     
=========================================
+ Hits          5788      5803   +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

'100_000_000',
'"1_00"',
'"10_00"',
'"100_00"',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct. It should be 10_000

million = 100_00_00
big_number = 100000_0000_000

.. versionadded:: 0.1.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please, add .. versionchanged:: 1.0.0 with an explanation: what has changed.

return string.lstrip("'").rstrip("'")


def _is_wrongly_underscored_number(string: str) -> bool:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please, move this to logic/

'+1_000',
'+1_000.0',
'-1_000',
'-1_000.0',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are also cases like 1.0_0, please test them.

@mmmylnikov
Copy link
Copy Markdown
Contributor Author

mmmylnikov commented Dec 13, 2024

@sobolevn, thank you for your feedback. In return, I am pleased to inform you that I have made the changes you requested.

However, I have a few questions or comments:

  1. Did I correctly understand that the case of numbers indicating a version:

  • 1.0_0 should be used in the "test_underscored_number" test (to identify as incorrect underscoring)
  • "1.0_0" should be used in the "test_correct_number" test (to identify as acceptable if specified as a string)
  1. I am not sure if I correctly moved the is_wrongly_underscored_number function to
    logic/tokens/strings.py

'"1.0_0"',
'"3_3.3"',
'"1_0_0"',
'"1_0_0_1"',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These numbers are not correct. Number can only considered correct if after split on _:

  • First group has length of 1, 2 or 3
  • All other groups have length of strictly 3

The same with float numbers: we split on . and apply this rule to the float part as well:

  • 0.0_005 is correct
  • 100_000.000_001 is correct
  • 0.00_05 is not correct

Copy link
Copy Markdown

@yurgers yurgers Dec 13, 2024

Choose a reason for hiding this comment

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

I will take part in your discussion.

is the number "1.0_0" considered a number?
or should it be interpreted as a string value, due to the fact used that there are quotes in quotes.

I was earlier to see a used shortened SemVer, an example: version = "2.4_15".
and it was just a string field.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, sorry. I missed these quotes. Please, add a comment that you also test strings.

'-100_0',
'1000_000',
'-1000_000',
'1.0_0',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please increase coverage of invalid float numbers. Add: 0_0.00_1 and 0.000_1

@mmmylnikov
Copy link
Copy Markdown
Contributor Author

@sobolevn , sorry for the mistake. I misunderstood the problem with floating point numbers. I've made edits and added more test cases.

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you! Congrats on your first PR :)

@sobolevn sobolevn merged commit a7b2e6f into wemake-services:master Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework WPS303: it should only be possible to write _ with 3 digits on the right

3 participants