-
Notifications
You must be signed in to change notification settings - Fork 905
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
Investigate best way to fix and fix MyPy failure on pipeline_registry.py
in default template
#2526
Comments
This line makes MyPy happy but it's not as nice: pipelines["__default__"] = sum(pipelines.values(), start=Pipeline([])) |
Hmm, this is an annoying one. I'm sure other people must have come across this also since it's pretty common to do Does it help if we add a type annotation to
Definitely I'd prefer to not explicitly specify |
I think the problem is that I think there only ways are either ignoring the error (always feels like surrender 🏳️) or try to assure MyPy that somehow pipelines["__default__"] = sum(pipelines.values()) or Pipeline([]) still looks meh but at least one does not need to know about the obscure |
I feel like overriding the sum return type should work, like so: from typing import Iterable, overload
@overload
def sum(__iterable: Iterable[Pipeline]) -> Iterable[Pipeline]: ... The idea is to override https://github.com/python/typeshed/blob/dd2818a41db6cd31e4680abf5e1362a7e5bfb5a6/stdlib/builtins.pyi#L1731-L1748. I need to test this properly, though; whatever I'm changing seems to be magically make |
This is a mostly harmless code change and would allow us to introduce MyPy as a linter. Is anybody strongly opposed to #2526 (comment) or #2526 (comment) ? |
I am not strongly opposed but I am opposed enough to leave a comment 😀 I think that If it's too difficult to get something like that working then changing |
pipeline_registry.py
in default templatepipeline_registry.py
in default template
I'm leaving this to whoever takes the ticket, since all solutions are quite small and doesn't seem to be consensus about that, but it's also quite minor |
Description
The default template has this code in
pipeline_registry.py
:kedro/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/pipeline_registry.py
Lines 14 to 15 in 7f44733
However, latest MyPy version (1.2.0 at the time of writing) doesn't have a high opinion on that snippet:
I tested this on Python 3.10 with the default MyPy settings. I think it's reasonable because
sum
has a defaultstart=0
, therefore if thepipelines
list is empty, the result has a different type:Context
The reason why
sum(pipelines)
works at all if because of this:kedro/kedro/pipeline/pipeline.py
Lines 184 to 186 in 7f44733
which naturally allows this nice syntactic sugar by making this work:
Steps to Reproduce
mypy
on itExpected Result
The project templates should produce statically correct code, and give no MyPy errors.
Your Environment
Include as many relevant details about the environment in which you experienced the bug:
pip show kedro
orkedro -V
): 0.18.7python -V
): 3.10.9The text was updated successfully, but these errors were encountered: