-
Notifications
You must be signed in to change notification settings - Fork 13
CFE-4559: cfbs convert, part 2
#276
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
Conversation
|
Thanks for submitting a PR! Maybe @craigcomstock can review this? |
larsewi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 🚀 Some minor comments
|
|
||
| from cfbs.utils import dict_sorted_by_key, file_sha256 | ||
|
|
||
| Version = str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider making this a class that inherrits string. You could overwrite the __lt__, __le__, etc. magic functions. Then you could use min() and max() directly on that type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, the intention was to make that change separately, though. Especially since other code uses functions using this type.
| other_versions_files = sorted(other_versions_files) | ||
| files_to_delete = [] | ||
| for ov_file, other_versions in other_versions_files: | ||
| # don't display all versions (which is an arbitrarily-shaped sequence), instead choose the most relevant one: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by arbitrarily-shaped sequence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that since the list of the multiple other versions might be incontiguous, it can't be displayed as a range, for example. So it's best to simply not display all the versions and instead choose one.
… type hints Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
larsewi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 🚀
| # Unfortunately, Pyright can not infer that these can't be `None` when `other_versions` is non-empty. | ||
| assert highest_other_version is not None | ||
| assert lowest_other_version is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These asserts are repeating, maybe it's more useful if we change highest_version and lowest_version to never return None, i.e. to not accept empty iterables? I checked the other places where highest_version() is used, and it doesn't seem like a bad change.
| def highest_version(versions: Iterable[Version]): | ||
| return max(versions, key=version_as_comparable_list, default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref the asserts and comments below;
| def highest_version(versions: Iterable[Version]): | |
| return max(versions, key=version_as_comparable_list, default=None) | |
| def highest_version(versions: Iterable[Version]) -> Version: | |
| result = max(versions, key=version_as_comparable_list, default=None) | |
| assert result is not None, "highest_version() does not accept empty lists / iterables" | |
| return result |
And the same for lowest_version() - Then, the return type for these are simpler, and it's incorrect to call them with an empty list.
No description provided.