Skip to content

Conversation

@jakub-nt
Copy link
Contributor

No description provided.

jakub-nt added 12 commits July 30, 2025 17:27
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Typing was incorrect, name was unclear

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
…nts, and changed cfbs command functions with `git_magic` decorators to always return `Result` before decoration

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
This fixes Python type checking tooling being confused about return types of functions decorated by the `git_magic` decorator - apparently, an explicit return type hint is needed for correct functioning even when the return type is correctly inferred

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
The command functions never return `Result`, and pyright now understands that.

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
The former name was highly generic and did not explain the purpose of the class.

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
This is useful in case more helper types are added.

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
The explicit type hints have been removed because they are redundant and could be a conflicting second source of truth

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt requested a review from olehermanse July 30, 2025 15:33
jakub-nt added 2 commits July 30, 2025 17:53
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt force-pushed the code-improvements-types branch from 4980548 to 2d7b745 Compare July 30, 2025 15:54
@olehermanse olehermanse requested a review from larsewi July 31, 2025 12:03
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.

Thanks for working on this 🚀

def search_command(terms: List[str]):
The return type (after any decoration) of the cfbs command functions is `CFBSCommandExitCode`.
This type is indistinguishably defined to be `int`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This type is indistinguishably defined to be `int`.
This type is defined to be `int`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two ways to define a type like that, one where you can pass the underlying type as the type and there's no type error, and one where there is a type error and you have to explicitly construct an instance of the type. The point behind this word was to highlight which one of the two this is (the former).

def search_command(terms: List[str]) -> int:
def search_command(terms: List[str]):
The return type (after any decoration) of the cfbs command functions is `CFBSCommandExitCode`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Defined a CFBSCommandExitCode type to improve maintainability

How does this improve maintainability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's similar to a constant variable. For example, suppose one wanted to redefine the type from int to something else, then without this definition, one would have to find the several places that would need changing, and replace the type in every single one. With this definition, one can just replace it once in the variable definition.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, it could be argued that the extra obfuscation / indirection makes it harder to read, not easier. Usually, making sure it's easy to read / understand is more important than making it easy to change, but YMMV.

@olehermanse olehermanse merged commit 5acb552 into cfengine:master Aug 1, 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.

3 participants