Describe the bug
If I generate a migration file with tortoise migrate for a model that contains a CharEnumField, and then run mypy on my project, it produces an error. The reason seems to be that CharEnumField does not return an instance of Field.
When the migration creates a new table (ops.CreateModel) the following error is printed:
error: List item 1 has incompatible type "tuple[str, ExampleEnum]"; expected "tuple[str, Field[Any] | ManyToManyRelation[Any] | None]" [list-item]
When the migration adds a CharEnumField to an existing table, the following error is printed:
error: Argument "field" to "AddField" has incompatible type "ExampleEnum"; expected "Field[Any] | ManyToManyRelation[Any] | None" [arg-type]
To Reproduce
Below is a minimal reproducible example.
models.py:
from tortoise.fields import CharEnumField
from tortoise.models import Model
import enum
class ExampleEnum(enum.StrEnum):
Value1 = enum.auto()
Value2 = enum.auto()
class ExampleModel(Model):
field: ExampleEnum = CharEnumField(ExampleEnum)
config.json:
{
"connections": {
"default": "sqlite://:memory:"
},
"apps": {
"monitor": {
"models": ["models"],
"migrations": "migrations",
"default_connection": "default"
}
}
}
Steps to reproduce:
tortoise --config-file config.json makemigrations
mypy migrations
Expected behavior
No mypy errors on scripts that are generated by Tortoise.
Describe the bug
If I generate a migration file with
tortoise migratefor a model that contains aCharEnumField, and then run mypy on my project, it produces an error. The reason seems to be thatCharEnumFielddoes not return an instance ofField.When the migration creates a new table (
ops.CreateModel) the following error is printed:When the migration adds a
CharEnumFieldto an existing table, the following error is printed:To Reproduce
Below is a minimal reproducible example.
models.py:
config.json:
{ "connections": { "default": "sqlite://:memory:" }, "apps": { "monitor": { "models": ["models"], "migrations": "migrations", "default_connection": "default" } } }Steps to reproduce:
tortoise --config-file config.json makemigrationsmypy migrationsExpected behavior
No mypy errors on scripts that are generated by Tortoise.