refactor(ChangelogFormat): refactor get_metadata_from_file for better readability and type#1596
Conversation
| unreleased = self.parse_title_level(line) | ||
| lines = file.readlines() | ||
| for index, line in enumerate(line.strip().lower() for line in lines): | ||
| parsed_unreleased_level = self.parse_title_level(line) |
There was a problem hiding this comment.
I think we can assume that self.parse_title_level is always a pure function? Then we don't have to call it twice here.
There was a problem hiding this comment.
If we want to make this assumption, we'll need to make this a static method instead, which makes sense but could be seen as a breaking change.
There was a problem hiding this comment.
but making that a static method is a good idea
| out_metadata.latest_version_position = index | ||
| break # there's no need for more info | ||
| if meta.unreleased_start is not None and meta.unreleased_end is None: | ||
| meta.unreleased_end = index |
There was a problem hiding this comment.
This index is unbounded if the file is empty, although this never happens for all code paths
2bdf3cf to
54e4288
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1596 +/- ##
==========================================
+ Coverage 97.33% 98.25% +0.91%
==========================================
Files 42 58 +16
Lines 2104 2692 +588
==========================================
+ Hits 2048 2645 +597
+ Misses 56 47 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
… readability and better type
54e4288 to
edf22a8
Compare
| unreleased = self.parse_title_level(line) | ||
| lines = file.readlines() | ||
| for index, line in enumerate(line.strip().lower() for line in lines): | ||
| parsed_unreleased_level = self.parse_title_level(line) |
There was a problem hiding this comment.
If we want to make this assumption, we'll need to make this a static method instead, which makes sense but could be seen as a breaking change.
| unreleased: int | None = None | ||
| if "unreleased" in line: | ||
| unreleased = self.parse_title_level(line) | ||
| lines = [line.strip().lower() for line in file.readlines()] |
There was a problem hiding this comment.
loop through it twice, probably not worth it?
… readability and better type
Description
Checklist
Code Changes
poetry alllocally to ensure this change passes linter check and testsDocumentation Changes
poetry doclocally to ensure the documentation pages renders correctlyExpected Behavior
Steps to Test This Pull Request
Additional Context