-
-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find a way to split types by Django version #1244
Comments
Parsing the stubs into multiple versioned, committed files is an interesting approach. We may not even need something as complex as libcst to do it, a few choice regexes could work, or the Cog tool for processing text with inline Python. |
Having conditional checks against the Django version is interesting but might be verbose e.g. for newly added arguments. Consider the new if DJANGO_5:
def __init__(
self,
# All the other arguments
db_default: type[NOT_PROVIDED] | Expression | _ST = ...,
): ...
else:
# The same `__init__` method without `db_default` And this for all Django fields. As the django-stubs versioning seems to now be inline with the Django versions, maybe we could consider the |
It's possible, but personally I have no interest in the maintenance work involved: backporting, maintaining old branches and doing twice the releases. If someone else were to handle it, maybe, but I suspect it would still affect the rest of maintainers in one way or another. My projects using django-stubs are have been one Django release behind for a while and I don't think I ever had any typing issues due to differing APIs between Django versions. And I can only remember one issue reported to us about this. My impression is that Django public APIs change rarely enough that this tends not to be an issue. With the example |
You're right, considering this it might not be worth maintaining two branches. Maybe in the future this would be a builtin feature when writing stubs. |
Looks like we follow |
Mypy supports splitting types by Python versions by interpreting
if sys.version_info ...
checks. But we have no mechanism to conditionally split types by Django version. This has lead to lots of small issues where Django’s API has changed and we cannot have correct types for all versions we attempt to support.To counter this problem, @sobolevn suggested doing releases per Django version, where we only officially support the latest version: #1095 (comment) . This is going to be the easiest for the time being, but if we can find a mechanism to split types by Django version, we could backtrack on this decision.
Related Mypy issue: python/typing#693
@ngnpope investigated a possibility with literal numerical types: #1160 (comment) . If we could supply the literal numerical type for the Django version from the MYpy plugin, then perhaps Mypy could use the type of that for conditions in stub files.
The text was updated successfully, but these errors were encountered: