-
Notifications
You must be signed in to change notification settings - Fork 928
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
Replace a StopIteration
exception with for-else
#3273
Conversation
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok <[email protected]>
Signed-off-by: Nok <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loving it ❤️
No comment on the implementation (deferring to other engineers), just wanted to remind that this is not a fix to #2943. Just tested it and the error messages are the same and the import errors still get shadowed. |
@astrojuanlu It says in the PR description "this will help us to fix #2943 and improve kedro.io.core" so it's not meant as a complete fix. |
I know, but GitHub will automatically close it, so I wrote the comment for future reference 😅 |
so elegant and now I actually have an example when this comes up! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine this took a while to figure out! Nice improvement ⭐
* Replace a `StopIteration` exception with for-else Signed-off-by: Nok Lam Chan <[email protected]> * fix the logic Signed-off-by: Nok <[email protected]> * bug fix Signed-off-by: Nok <[email protected]> --------- Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]>
* Configure `ruff format`, use it instead of `black` (#3258) * build: format code with `ruff format` over `black` Signed-off-by: Deepyaman Datta <[email protected]> * style(ruff-format): format code with `ruff format` Signed-off-by: Deepyaman Datta <[email protected]> --------- Signed-off-by: Deepyaman Datta <[email protected]> * docs: fix typos (#3270) Signed-off-by: Ajay Gonepuri <[email protected]> Co-authored-by: Jo Stichbury <[email protected]> * Update create_a_pipeline.md (#3213) * Update create_a_pipeline.md typo: --nodes=preprocess_shuttles_node needs to be specified Signed-off-by: Pranav Dave <[email protected]> * Use both node names Signed-off-by: Juan Luis Cano Rodríguez <[email protected]> * Update create_a_pipeline.md Signed-off-by: Jo Stichbury <[email protected]> --------- Signed-off-by: Pranav Dave <[email protected]> Signed-off-by: Juan Luis Cano Rodríguez <[email protected]> Signed-off-by: Jo Stichbury <[email protected]> Co-authored-by: Juan Luis Cano Rodríguez <[email protected]> Co-authored-by: Jo Stichbury <[email protected]> * Replace a `StopIteration` exception with for-else (#3273) * Replace a `StopIteration` exception with for-else Signed-off-by: Nok Lam Chan <[email protected]> * fix the logic Signed-off-by: Nok <[email protected]> * bug fix Signed-off-by: Nok <[email protected]> --------- Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]> * Make `ruff format` happy Signed-off-by: Deepyaman Datta <[email protected]> * Make `ruff` happy Signed-off-by: Deepyaman Datta <[email protected]> --------- Signed-off-by: Deepyaman Datta <[email protected]> Signed-off-by: Ajay Gonepuri <[email protected]> Signed-off-by: Pranav Dave <[email protected]> Signed-off-by: Juan Luis Cano Rodríguez <[email protected]> Signed-off-by: Jo Stichbury <[email protected]> Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]> Co-authored-by: Deepyaman Datta <[email protected]> Co-authored-by: Ajay Gonepuri (GONAPCORP) <[email protected]> Co-authored-by: Jo Stichbury <[email protected]> Co-authored-by: Pranav Dave <[email protected]> Co-authored-by: Juan Luis Cano Rodríguez <[email protected]> Co-authored-by: Nok Lam Chan <[email protected]>
…encies is missing (#3272) * release note Signed-off-by: Nok Chan <[email protected]> * Refactor - split `class_obj` into `class_obj` and `dataset_type` Signed-off-by: Nok Chan <[email protected]> * bug fix Signed-off-by: Nok Chan <[email protected]> * Replace a `StopIteration` exception with for-else (#3273) * Replace a `StopIteration` exception with for-else Signed-off-by: Nok Lam Chan <[email protected]> * fix the logic Signed-off-by: Nok <[email protected]> * bug fix Signed-off-by: Nok <[email protected]> --------- Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]> * If module exists, raise error even it is ModuleNotFoundError Signed-off-by: Nok Chan <[email protected]> * simplify load_obj Signed-off-by: Nok Chan <[email protected]> * minor bug fix, check if class exist Signed-off-by: Nok Chan <[email protected]> * remove obsolete test Signed-off-by: Nok Chan <[email protected]> * object is a bad type hint Signed-off-by: Nok Chan <[email protected]> * update error message link to installation guide Signed-off-by: Nok Chan <[email protected]> * add tests Signed-off-by: Nok Chan <[email protected]> * Change error message Signed-off-by: Nok Chan <[email protected]> * Update docstring Signed-off-by: Nok Chan <[email protected]> * fix lint Signed-off-by: Nok Chan <[email protected]> --------- Signed-off-by: Nok Chan <[email protected]> Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]>
* Replace a `StopIteration` exception with for-else Signed-off-by: Nok Lam Chan <[email protected]> * fix the logic Signed-off-by: Nok <[email protected]> * bug fix Signed-off-by: Nok <[email protected]> --------- Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Nok <[email protected]> Signed-off-by: Suvrakamal Das <[email protected]>
Description
I have read the logic how Kedro import datasets many time, I finally realise this can be simplified with
for-else
. It also reveals a hidden bug.kedro/kedro/io/core.py
Lines 380 to 396 in 38dfe6f
class_obj
can beNone
, addingstr
toNone
result in type error but this is hidden by theload_obj
This is only a few lines of change but take me a while to figure it out, the error was complicated due to many layers of try-except. this will help us to fix #2943 and improve
kedro.io.core
Development notes
I refactor some logic in a separate PR, the
class_obj
was overused and make it very hard to debug.Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-by
line in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
RELEASE.md
file