Skip to content

Conversation

@olehermanse
Copy link
Member

@olehermanse olehermanse commented Jul 3, 2025

No description provided.

@olehermanse olehermanse added the WIP Work in progress label Jul 3, 2025
@olehermanse olehermanse force-pushed the pyright branch 8 times, most recently from e8680ed to ca25e28 Compare July 3, 2025 20:09
@olehermanse olehermanse changed the title Added pyright to GH Actions and fixed errors Added pyright, pyflakes, and flake8 to GH Actions Jul 3, 2025
@olehermanse olehermanse requested a review from larsewi July 3, 2025 20:12
@olehermanse olehermanse removed the WIP Work in progress label Jul 3, 2025
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Ticket: CFE-4554
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
@olehermanse olehermanse changed the title Added pyright, pyflakes, and flake8 to GH Actions CFE-4554: Added pyright, pyflakes, and flake8 to GH Actions Jul 4, 2025
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
@olehermanse olehermanse requested a review from jakub-nt July 4, 2025 10:54


def read_json(path) -> OrderedDict:
def read_json(path) -> Union[OrderedDict, None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems weird, perhaps it would be better to not return None and instead use exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I think several suggested asserts should instead be handled exceptions. Some of them might be due to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems weird, perhaps it would be better to not return None and instead use exceptions.

In general, there's nothing weird or wrong about having a function which returns None on error. In some cases it might be nicer, in other using an exception can have benefits.

In general, I think several suggested asserts should instead be handled exceptions. Some of them might be due to this.

Yea, some of them should be, however making the assumptions explicit with asserts and enabling stricter enforcement for PRs going forward is still an improvement. Converting the codebase to try to exhaustively handle all error cases will be a bit bigger effort that is outside the scope of this PR.

Copy link
Contributor

@jakub-nt jakub-nt Jul 4, 2025

Choose a reason for hiding this comment

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

I think assert is not the right tool for the job of checking conditions like whether a file exists or not, I think it's rather for checking state that should never be wrong if there are no programming logic mistakes. They can even be disabled. I'm fine with allowing it for the moment in this PR, though. I was just concerned that pyright is suggesting adding such asserts.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think assert is not the right tool for the job of checking conditions like whether a file exists or not, I think it's rather for checking state that should never be wrong if there are no programming logic mistakes. They can even be disabled. I'm fine with allowing it for the moment in this PR, though. I was just concerned that pyright is suggesting adding such asserts.

Correct, it is not. asserts are a tool for highlighting programmer's mistakes and making assumptions explicit. That can include whether files exist or not. Currently the code assumes that a file exists in certain places, and it's better that this assumption is explicit rather than implicit.

Copy link
Contributor

@jakub-nt jakub-nt left a comment

Choose a reason for hiding this comment

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

Can always adjust whatever in future PRs

@olehermanse olehermanse merged commit 69c8598 into cfengine:master Jul 4, 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.

2 participants