Mypy error: Variable "Email" is not valid as a type mypy(error)
See original GitHub issueTaking the example from the readme:
import marshmallow
from marshmallow_dataclass import NewType
Email = NewType("Email", str, field=marshmallow.fields.Email)
When using Email in a schema, for instance:
@marshmallow_dataclass.dataclass
class MySchema:
id: str = field(metadata={"validate": marshmallow.validate.uuid})
email: Email
Schema: ClassVar[Type[marshmallow.Schema]] = marshmallow.Schema
I’m getting this error from mypy:
Mypy error: Variable "Email" is not valid as a type mypy(error)
versions:
marshmallow==3.2.1
marshmallow-dataclass==7.0.0
Thanks in advance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
mypy "is not valid as a type" for types constructed with `type()`
mypy complains error: Variable "packagename.
Read more >dynamic base class "error: Variable ... is not valid as a type ...
dynamic base class "error: Variable ... is not valid as a type" when it is the parameter to a function and typed as...
Read more >Common issues and solutions - mypy 0.991 documentation
There are several common reasons why obviously wrong code is not flagged as an error. The function containing the error is not annotated....
Read more >python/typing - Gitter
Hi all, I'm trying to use a mypy plugin to essentially remove an attribute from a class such that when that attribute is...
Read more >Mypy Documentation - Read the Docs
Python interpreter to run your code, even if mypy reports errors. ... mypy will use the provided type hints to detect incorrect use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I opened an issue at mypy, and they do not seem to be keen on implementing anything that would allow us make
NewType
work with mypy: https://github.com/python/mypy/issues/7901I am going to leave this issue open, and if anyone is interested in writing a mypy plugin, we’ll track progress here.
Correct me if I’m wrong, but don’t think this is related to
marshmallow_dataclass
. mypy cannot handle any dynamically created types.Your code can be reduced to the following, that mypy also rejects:
This also gives:
error: Variable "Email" is not valid as a type