mypy: invalid type comment or annotation
See original GitHub issueHi,
I think this issue related more to mypy
, but maybe you know about any workaround or how to solve this.
Here is my code:
class Test(BaseModel):
k: constr(min_length=2)
And when I run mypy
I got:
error: invalid type comment or annotation
note: Suggestion: use constr[...] instead of constr(...)
Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:42
- Comments:38 (15 by maintainers)
Top Results From Across the Web
mypy: invalid type comment or annotation · Issue #156 - GitHub
To anyone still running into this, # type: ignore now works. Its error code if you want to be pedantic (heh) is valid-type...
Read more >mypy "invalid type" error - python - Stack Overflow
I'm trying to implement type annotations in a current project, and am receiving errors from mypy that I don't understand. I'm using Python...
Read more >Common issues and solutions - mypy 0.991 documentation
A # type: ignore comment at the top of a module (before any statements, including imports or docstrings) has the effect of ignoring...
Read more >mypy's response to that code: error:invalid type comment or ...
error:invalid type comment or annotation note:Suggestion: use intBit[...] instead of intBit(...) So what's really happening is the type ...
Read more >python/mypy - Gitter
Is there a way to force mypy to ignore a line completely? # type: ignore does not suppress error: invalid type comment or...
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 Free
Top 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
This should be mentioned in the documentation:
https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
is incompatible with mypy at the moment
The above is not quite right as well, because the first parameter to
Field
is the default value. In this case the default would be the typestr
, which is not astr
.Another possible issue is that a default value was supplied, making this field optional.
Updated example:
If you want to make the field a Required field, use an ellipsis:
Something like
required=True
would feel more natural, but that’s not an option as of v1.4. Please be aware that supplying a default ofNone
is not the same as supplying no default value.