Skip to content
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

feat(checks): detect extra curly braces in Python brace format #12198

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

nijel
Copy link
Member

@nijel nijel commented Aug 5, 2024

Proposed changes

Fixes #12197

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

Other information

@nijel nijel added this to the 5.7 milestone Aug 5, 2024
@nijel nijel requested a review from orangesunny as a code owner August 5, 2024 09:54
@nijel nijel self-assigned this Aug 5, 2024
@nijel nijel enabled auto-merge (rebase) August 5, 2024 09:54
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.34%. Comparing base (6aee586) to head (941373b).
Report is 2988 commits behind head on main.

Files Patch % Lines
weblate/checks/format.py 94.44% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12198      +/-   ##
==========================================
- Coverage   90.82%   90.34%   -0.48%     
==========================================
  Files         554      583      +29     
  Lines       57306    59966    +2660     
  Branches     9122     9604     +482     
==========================================
+ Hits        52046    54176    +2130     
- Misses       3640     3993     +353     
- Partials     1620     1797     +177     
Files Coverage Δ
weblate/checks/tests/test_format_checks.py 100.00% <100.00%> (ø)
weblate/checks/format.py 93.13% <94.44%> (-0.70%) ⬇️

... and 394 files with indirect coverage changes

@nijel nijel merged commit c006da8 into WeblateOrg:main Aug 5, 2024
32 checks passed
@nijel nijel deleted the check-brace branch August 5, 2024 12:12
@buhtz
Copy link

buhtz commented Aug 5, 2024

Thank you for this quick response.
I am not sure but the code looks like that it wouldn't catch all situations. And I don't understand the unit tests. The test code is not self explaining and has no comments. It is not clear for me which one of the cases should be an error and which not.

Other cases:

  • "foo }bar{" (seems not to fail in your code)

Maybe my own solution (related to PR bit-dev/backintime#1829) using a combination of regex can give you some inspiration.

I also encountered strings like this: "{{foobar}}". I am aware that this is a valid Python string to escape curly brackets. But in real world in most cases this is a typo from the translator. So if you see a possibility it would be nice if Weblate could warn about that, too. Or maybe compare it to the original string and look if there are escaped brackets, too.

EDIT: And just a learning question for me as a maintainer. Don't you have a review policy for code changes in your project? Aren't there other reviews in the team?

@@ -340,7 +344,9 @@ def normalize(self, matches: list[str]) -> list[str]:
def extract_matches(self, string: str) -> list[str]:
return [self.cleanup_string(x[0]) for x in self.regexp.findall(string)]

def check_format(self, source: str, target: str, ignore_missing, unit: Unit):
def check_format(
Copy link

Choose a reason for hiding this comment

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

The doc strings has potential to be improved. Not clear what it does. Arguments and return values are unclear.

Because of that I am unable to value the new unit tests using this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, the documentation always has potential to get improved. Currently, I'm at least focusing on adding type annotations when touching the code.

nijel added a commit to nijel/weblate that referenced this pull request Aug 5, 2024
- look for escaped braces in the original string as well
- treat { } escapes same as with %
- remove bogus detection of % placeable
- detect any stray { } besides parsed format string

See WeblateOrg#12198 and WeblateOrg#12197
@nijel
Copy link
Member Author

nijel commented Aug 5, 2024

#12199 should improve this.

There is currently nobody to do a review, but I hope this to change soon as some new team members will get fully onboarded.

@buhtz
Copy link

buhtz commented Aug 5, 2024

Are you and the planed reviewers employed by Weblate company?
You might contact the Codeberg.org community and people. The might have capacity and they depend on Weblate.

nijel added a commit that referenced this pull request Aug 5, 2024
- look for escaped braces in the original string as well
- treat { } escapes same as with %
- remove bogus detection of % placeable
- detect any stray { } besides parsed format string

See #12198 and #12197
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.

Detect to many curly brackets (Python)
2 participants