We do this mainly because we need to add some metadata to the union, and we can't use Annotated for two reasons:
it is currently broken for the usage we need (there's an issue for that)
we want to keep strawberry.union as the API as it looks better than the alternative to annotated.
That being said we managed to get a basic plugin working, but it breaks in some cases, here's the first one as I was able to reproduce it in a minimal repo.
We running mypy on this example:
from __future__ importannotationsimportstrawberryx: MyUnionMyUnion=strawberry.union("Entity", types=(str, int))
reveal_type(MyUnion)
reveal_type(x)
we get this error:
example.py:7: error: Cannot assign multiple types to name "MyUnion" without an explicit "Type[...]" annotation
example.py:10: note: Revealed type is 'builtins.object'
example.py:11: note: Revealed type is 'Union[builtins.str, builtins.int]'
Found 1 error in 1 file (checked 1 source file)
if I move x: MyUnion below, everything works as expected, but I still think there's a bug in either mypy or the plugin I'm writing as we managed to get this issue in a different scenario too.
I've set up a repo with the minimal code for this issue:
I can't remember the reason behing me adding that flag as False I guess it should be true in this case, but looks like it isn't doing much (for this specific use case)
EDIT:
I don't know if it helps, but this is what happens with defer:
patrick91 commentedOct 22, 2020
Hello there, I'm working on a plugin that allows this syntax:
to be equivalent of
We do this mainly because we need to add some metadata to the union, and we can't use Annotated for two reasons:
strawberry.union
as the API as it looks better than the alternative to annotated.That being said we managed to get a basic plugin working, but it breaks in some cases, here's the first one as I was able to reproduce it in a minimal repo.
We running mypy on this example:
we get this error:
if I move
x: MyUnion
below, everything works as expected, but I still think there's a bug in either mypy or the plugin I'm writing as we managed to get this issue in a different scenario too.I've set up a repo with the minimal code for this issue:
https://github.com/patrick91/mypy-issue/blob/main/plugin_1.py
I've also tried to defer the
add_symbol_table_node
to the final iteration, but looks like that did't work.Is this a bug in mypy or me using it wrong?
The text was updated successfully, but these errors were encountered: