Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1594 +/- ##
==========================================
- Coverage 91.85% 91.83% -0.02%
==========================================
Files 126 130 +4
Lines 7468 7573 +105
==========================================
+ Hits 6860 6955 +95
- Misses 608 618 +10
🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds a utility to quote integer values for specific keys in YAML files, ensuring fields like 'version' are correctly parsed as strings. Feedback indicates that the current regular expression is not robust enough to handle trailing whitespace or comments, and a more reliable regex pattern was suggested.
cognite/neat/_utils/text.py
Outdated
| pattern = rf"^(\s*-?\s*)?{key}:\s*(?!.*['\":])([\d_]+)$" | ||
| replacement = rf'\1{key}: "\2"' |
There was a problem hiding this comment.
The current regular expression is not robust. It will fail to match lines that contain comments or trailing whitespace. For example, version: 1_0_0 # My comment would not be matched, and the version would be incorrectly parsed as an integer, which is the problem this change is intended to solve.
Additionally, the negative lookahead (?!.*['\":]) is overly restrictive. For example, it would fail if a comment contained a quote: version: 1 # My "quoted" comment.
A simpler and more robust regex can achieve the desired outcome while correctly handling these cases.
| pattern = rf"^(\s*-?\s*)?{key}:\s*(?!.*['\":])([\d_]+)$" | |
| replacement = rf'\1{key}: "\2"' | |
| pattern = rf"^(\s*-?\s*{key}:\s*)([\d_]+)(.*)$" | |
| replacement = rf'\1"\2"\3' |
Description
I discovered this one while running Neat in Toolkit. This is fairly important for Neat as plugin in Toolkit as it currently blocks Neat from being applied to a lot of models.
Problem
When reading from YAML
When reading this with the YAML parser we get out
Thus
1_0_0which should have been a string, becomes the number 100.solution
This is technically not a bug, but a user mistake. They can write it
However, instead of requiring every user to know the details of how YAML parsing works, we automatically apply this fix to all version fields. This is the same thing we do in Toolkit, and that that has been very successful.
Bump
Changelog
Improved
yaml, Neat now handles integer in the version field of views and data models.