MyPy blows up on the exotic types that return types, e.g. conint
See original GitHub issuefrom pydantic import BaseModel, conint
class MyPyProblem(BaseModel):
big_int: conint(gt=1000, lt=1024) = None
mypy --verbose tests/test_pydantic_bug_report.py
LOG: Mypy version 0.620
LOG: Could not load cache for tests.test_pydantic_bug_report: .mypy_cache/3.6/tests/test_pydantic_bug_report.meta.json
LOG: Metadata not found for tests.test_pydantic_bug_report
LOG: Parsing tests/test_pydantic_bug_report.py (tests.test_pydantic_bug_report)
LOG: Bailing due to parse errors
LOG: Build finished in 0.001 seconds with 0 modules, and 2 errors
tests/test_pydantic_bug_report.py:4: error: invalid type comment or annotation
tests/test_pydantic_bug_report.py:4: note: Suggestion: use conint[...] instead of conint(...)
I tried both the recommendation of [] and aliasing it (e.g. BIG_INT=conint(gt=1000, lt=1024)
)
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
MyPy blows up on the exotic types that return types, e.g. conint
There's no more detail than Invalid type , what am I supposed to do with that? This works: from typing import cast from...
Read more >weixin_39611930的博客_CSDN博客-领域博主
fix some use of `snippet` in `types.rs`. 2021-01-12 ... MyPy blows up on the exotic types that return types, e.g. conint. 2021-01-12 ...
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 is the kind of thing I find very frustrating about mypy. There’s no more detail than
Invalid type
, what am I supposed to do with that?This works:
You have to use
cast(BigInt, 1001)
to avoid mypy whinging that1001
is not an instance ofBigInt
.Something like this works for me :
big_int: conint(gt=1000, lt=1024) = None # type: ignore