tortoise / tortoise/tortoise-orm
Incompatible types in assignment
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
Mypy throws an error if I try to assign value to a model field.
To Reproduce
class MyModel(tortoise.Model):
...
my_field = fields.BooleanField(default=False)
m = await MyModel.get(id=...)
m.deleted = True
await m.save()
>>> Mypy error: Incompatible types in assignment (expression has type "bool", variable has type "BooleanField")
Expected behavior
No mypy errors =)
Additional context
In django there is a similar problem and I should disable type check entirely or use django-stubs.
Tortoise, on the other hand, uses typing module heavily. Is there something that I can use to avoid such errors?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the MyModel example with a BooleanField assignment and running mypy. Investigate how model fields are typed and exposed to instances. Done means valid assignments such as m.deleted = True produce no mypy error while the model can still be saved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100