Skip to content
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

feat: check that async_early_return is applied on async functions #79

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

fgsalomon
Copy link
Contributor

No description provided.

@fgsalomon fgsalomon requested a review from acostapazo October 18, 2024 13:26
@fgsalomon
Copy link
Contributor Author

To me this should be handled by custom lint rules but ruff still doesn't provide a plugin system like flake8 does.

@acostapazo
Copy link
Contributor

To me this should be handled by custom lint rules but astral-sh/ruff#283 like flake8 does.

Yes, in the meantime, we can apply solutions similar to what you proposed. We should also implement something similar onearly_return in async functions.

Should we return a Failure(AsyncDecorationError()) or maybe we just raise an exception and stop the runtime as we do in https://github.com/alice-biometrics/meiga/blob/main/meiga/result.py#L69

@acostapazo
Copy link
Contributor

Otherwise, you have followed the same definition as UnexpectedDecorationOrderError, UnexpectedDecorationOrderError so probably it is ok 🤔

         if isinstance(func, staticmethod):
                return Failure(UnexpectedDecorationOrderError())  # type: ignore
            elif isinstance(func, classmethod):
                return Failure(UnexpectedDecorationOrderError())  # type: ignore
            elif not inspect.iscoroutinefunction(func):
                return Failure(AsyncDecorationError())  # type: ignore

@fgsalomon
Copy link
Contributor Author

Otherwise, you have followed the same definition as UnexpectedDecorationOrderError, UnexpectedDecorationOrderError so probably it is ok 🤔

         if isinstance(func, staticmethod):
                return Failure(UnexpectedDecorationOrderError())  # type: ignore
            elif isinstance(func, classmethod):
                return Failure(UnexpectedDecorationOrderError())  # type: ignore
            elif not inspect.iscoroutinefunction(func):
                return Failure(AsyncDecorationError())  # type: ignore

I was going to throw an exception but I saw that and followed suit.

@fgsalomon
Copy link
Contributor Author

I guess we can use custom code inspections in PyCharm to detect this kind of things:
image

@acostapazo acostapazo merged commit 1fca6c6 into main Oct 21, 2024
26 checks passed
@acostapazo acostapazo deleted the feature/async-early-return-coroutine-check branch October 21, 2024 11:29
@fgsalomon
Copy link
Contributor Author

To me this should be handled by custom lint rules but ruff still doesn't provide a plugin system like flake8 does.

I've just discovered Fixit. I think it should be easy to write a custom rule with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants