-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
Inheritance from models fields #285
Comments
Can you try completing the annotation on your init definition?
and type your options variable:
|
I did and But I still get |
I also have the same class AutoDateTimeField(models.DateTimeField):
"""
A custom model field based on :class:`django.db.models.DateTimeField` that
updates itself to `django.utils.timezone.now()` upon updating it's model.
"""
def pre_save(self, model_instance, add) -> datetime:
"""
Hook to timestamp model before it's saved.
"""
return timezone.now() Any workaround? |
All fields are generic with kind of 2: https://github.com/typeddjango/django-stubs/blob/master/django-stubs/db/models/fields/__init__.pyi#L45 You can try to do something like this: from typing import TypeVar
# __set__ value type
_ST = TypeVar("_ST")
# __get__ return type
_GT = TypeVar("_GT")
class AutoDateTimeField(models.DateTimeField[_ST, _GT]):
... |
@sobolevn doesn't work, it results in:
|
That because of django/django#12405 Sadly, I don't have any ideas on how to fix it except |
Just for reference: this can be fixed now with import django_stubs_ext
django_stubs_ext.monkeypatch() |
The three "ignore" directives are: - avoid unreadable boilerplate from inherited `Field` methods; and: - typeddjango/django-stubs#285 (comment)
I encountered this error because I was typing something that was already implicitly typed correctly: - name: models.CharField = models.CharField(max_length=100, primary_key=True)
+ name = models.CharField(max_length=100, primary_key=True) |
I've got the following snippet
And there are two problems:
First -
models.py:3 error: Missing type parameters for generic type "CharField"
And second
How can I annotate generic CharField?
And how can I pass kwargs to super?
The text was updated successfully, but these errors were encountered: