Skip to content

Conversation

@jakub-nt
Copy link
Contributor

No description provided.

@cf-bottom
Copy link

Thanks for submitting a PR! Maybe @craigcomstock can review this?

@jakub-nt jakub-nt marked this pull request as ready for review August 25, 2025 14:07
Copy link
Contributor

@larsewi larsewi left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

@jakub-nt jakub-nt Aug 25, 2025

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:
Copy link
Contributor

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?

Copy link
Contributor Author

@jakub-nt jakub-nt Aug 25, 2025

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>
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Good job 🚀

Comment on lines +174 to +176
# 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
Copy link
Member

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.

Comment on lines +147 to 148
def highest_version(versions: Iterable[Version]):
return max(versions, key=version_as_comparable_list, default=None)
Copy link
Member

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;

Suggested change
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.

@olehermanse olehermanse merged commit 4c330a1 into cfengine:master Aug 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants