-
-
Notifications
You must be signed in to change notification settings - Fork 485
Custom field typing #545
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
Comments
I have the same issue. Does anyone know how to get this working? |
This is still happening in the latest release. Is this not considered to be a bug? |
Same question over here... |
I'm currently facing the same issue, which I believe to be related to what's described in #336. Any insights or updates on this? @sobolevn maybe? :) |
Any updates on getting type checking working on custom model fields? I'm currently trying to get this to work to no avail! |
This works for me: from django.db import models
class Custom(models.Field[str, int]):
...
class MyModel(models.Model):
custom = Custom()
def some(m: MyModel):
reveal_type(m.custom) # N: Revealed type is "builtins.int"
m.custom = ['a'] # E: Incompatible types in assignment (expression has type "list[str]", variable has type "str") |
If you can reproduce the issue and fix it - please, send a PR! 🤝 |
I was able to get it working just now like this!
I found a reference in this PR which I followed :#2043 Thank you! 🙏 |
Should we add this workaround to the FAQ in the readme ? (I can send a pr if needed) |
@UnknownPlatypus sure :) |
I have a custom field type that looks like this:
And this works (revealed type is as expected) IF I define on models like so:
It does not work (revealed type is Any) if I do this:
No amount of futzing with multiple type parameters seems to fix this. Any ideas? |
Bug report
I'm trying to implement generic typing on custom fields, and I'm not having much luck. Any idea if there is a way to make this work?
What's wrong
Note: The following examples require hacking
django_stubs_ext.patch._need_generic
to includedjango.db.models.Field
, which is something I'll raise separately.I'm able to specify static typing for a custom field, but I'm not able to specify generic typing. Example code:
How is that should be
Have I missed something in my implementation, or is this not supported?
System information
python
version: 3.8.6django
version: 3.1.4mypy
version: 0.790django-stubs
version: 0.1.0The text was updated successfully, but these errors were encountered: