You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can this type information be exported? For example, for a django app/models.py plugin would generate typings/mypy/app/models.pyi with all the added types. I would run it like mypy export-plugin-types or something similar, when my code changes.
Other options
If there's another way to solve this problem, please help me.
My last attempt looks like this (but it returns BaseField, and not the child class like StringField. And when init arguments are changing, i need to redefine those overloads for a field specifically):
@last-partizan, I did something really similar for django with https://github.com/Viicos/django-autotyping/. The library provides a CLI to dynamically generate django stubs definitions matching your project and you can then configure your type checker to use the generate stubs as a source of truth for types. I don't think such a feature should live in mypy. Generating code can be hard, and there's many ways to do so.
Feature
Add a way to export generated types from a plugin (like
mypy_django_plugin
) aspyi
. So they can be used by other type checkers.Pitch
Few days ago i started an effort to migrate types from
mongo-types
into coremongoengine
, and i need to solve a problem:Each field can accept and return either
T
orT | None
, depending on therequired
property.In the
mongo-types
it was solved by adding__new__
overloads for each field, and it works well, but clutters the codebase.Similar problem exists for Django, and
django-stubs
are solving this by writing a mypy plugin, that changes__set__
and__get__
descriptors for a field, depending on the init argumens.Can this type information be exported? For example, for a django
app/models.py
plugin would generatetypings/mypy/app/models.pyi
with all the added types. I would run it likemypy export-plugin-types
or something similar, when my code changes.Other options
If there's another way to solve this problem, please help me.
My last attempt looks like this (but it returns BaseField, and not the child class like StringField. And when init arguments are changing, i need to redefine those overloads for a field specifically):
The text was updated successfully, but these errors were encountered: