Repository navigation
fix(data_function): -> None declares no outputs; refuse a returned value and positional-only parameters (ITL-1257, ITL-1258) #447
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
Open
eywalker
wants to merge
5
commits into
main
Choose a base branch
from
eywalker/itl-1257-function-pods-a-function-annotated-none
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8910859
fix(data_function): -> None declares no outputs; refuse a returned va…
1941515
fix(data_function): keep OutputTypeError's attributes; read a postpon…
f4a41d1
fix(data_function): copy output keys at construction; say the key nee…
c38f2e1
fix(schema_utils): resolve the return annotation on its own when anot…
25660cb
Revert "fix(schema_utils): resolve the return annotation on its own w…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ### Breaking changes and migration | ||
|
|
||
| - A function with no `output_keys` that returns a value other than `None` raises | ||
| `NoOutputsDeclaredError` (an `OutputTypeError`) instead of having the value dropped | ||
| (ITL-1257). To keep the value, declare an output key with its type (a return | ||
| annotation or `output_schema`); otherwise return nothing. | ||
|
|
||
| ### Fixed | ||
|
|
||
| - A function annotated `-> None` with no `output_keys` is accepted as a function with no | ||
| outputs, like a function with no return annotation (ITL-1257). It was refused ("has a | ||
| return type annotation, but no return keys were specified") because `typing.get_type_hints` | ||
| reads `-> None` as `NoneType`. `-> None` with `output_keys` is now refused when the pod is | ||
| created; it was accepted and gave an output column of type `NoneType`. | ||
| - A function with a positional-only parameter is refused when the pod is created, naming | ||
| the parameter (ITL-1258). A pod passes its inputs by name, so a call that supplied | ||
| such a parameter failed with a `TypeError` (one with a default worked only while the | ||
| input never held it, and the parameter could never be given). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ## `src/orcapod/core/data_function.py` — returned values not checked against the declared type | ||
|
|
||
| ### NR1 — `-> None` with no output keys was refused; a value returned with no outputs was dropped | ||
| **Status:** resolved | ||
| **Severity:** medium | ||
| **Issue:** ITL-1257 (related: ITL-1258) | ||
|
|
||
| `extract_function_schemas` (`utils/schema_utils.py`) has a branch for a function annotated | ||
| `-> None`: with no output keys it means no outputs, with output keys it is refused. The | ||
| branch was never reached, because `typing.get_type_hints` reads `-> None` as `NoneType`: | ||
| `-> None` with no output keys was refused ("has a return type annotation, but no return | ||
| keys were specified"), while `-> None` with one output key was accepted with an output | ||
| column of type `NoneType`. Separately, a function with no output keys that returned a | ||
| value had the value dropped silently (`parse_function_outputs`). | ||
|
|
||
| **Fix:** `extract_function_schemas` reads `NoneType` as `-> None`, so `-> None` with no | ||
| output keys means no outputs (as no return annotation does) and `-> None` with output keys | ||
| is refused at construction. A function with no output keys that returns a value other | ||
| than `None` raises `NoOutputsDeclaredError`, an `OutputTypeError`, at call time, on the | ||
| sync and the async path (developer: "declared `-> None` (or lack of any return type) should | ||
| be treated as empty return"). Tests: `tests/test_core/data_function/test_none_return.py`. | ||
| In the same change, a positional-only parameter is refused at construction (ITL-1258: a | ||
| call that supplied it failed; `test_positional_only.py`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/test_core/data_function/string_annotated_functions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Functions whose annotations are strings (``from __future__ import annotations``). | ||
|
|
||
| Used by ``test_none_return.py`` (ITL-1257): ``-> None`` read through | ||
| ``typing.get_type_hints`` from a string annotation. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
|
|
||
| def log_value(x: int) -> None: | ||
| """Declares no outputs.""" | ||
| del x | ||
|
|
||
|
|
||
| def log_value_unannotated(x: int): # no return annotation on purpose | ||
| """Declares no outputs by having no return annotation.""" | ||
| del x | ||
|
|
||
|
|
||
| def maybe(x: int) -> int | None: | ||
| """One output that may be null.""" | ||
| return None if x < 0 else x | ||
|
|
||
|
|
||
| def unresolvable_input(x: Missing) -> None: # noqa: F821 # pyright: ignore[reportUndefinedVariable] # unresolvable on purpose | ||
| """Declares no outputs; its parameter annotation cannot be resolved. | ||
|
|
||
| ``typing.get_type_hints`` fails on it, so the return annotation stays the text | ||
| ``"None"``; the input type is supplied with ``input_schema``. | ||
| """ | ||
| del x | ||
|
|
||
|
|
||
| def unresolvable_input_quoted(x: Missing) -> "None": # noqa: F821 # pyright: ignore[reportUndefinedVariable] # unresolvable on purpose | ||
| """As ``unresolvable_input``, with the return annotation written as a string. | ||
|
|
||
| The postponed annotation is then the text ``"'None'"``. | ||
| """ | ||
| del x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.