-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
main #792
Closed
Closed
main #792
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously the types required a mypy plugin to handle the generics, now we're using the builtin typing functionality. Probably more verbose, but it should work with type checkers besides mypy. Also remove `objects: BaseManager[Any]` from the base `Model` so subclasses will be required to explicitly declare it. Avoids uses having `.filter().first()` returning `Optional[Any]` instead of `Optional[T]`.
Bunch of misc changes: - Support for PG fields - Basic Django project to type check model fields - Nullability for most fields via the `null` argument.
Add basic psycopg2 type stubs and type more of django's raw sql related methods, e.g.: ``` with connection.cursor() as cur: cur.execute("select 1") ``` Add some other dev dependencies to make figuring out the types easier.
Param should probably be `Sequence[Any] | Dict[str, Any]` but I'm trying to see how far I can get before I have to do that.
Key change is to also fix HttpHeaders to such that `.get()` returns `str | None` instead of `Any | None`.
Poetry defaults to the system version, 3.7 in this case, which was preventing users of 3.6 from installing the package.
Poetry wouldn't install because a yaml file was in `django-stubs` https://github.com/python-poetry/poetry-core/blob/4bc9bde1d0ac201dcb5e20ac5b890dff3bd47b07/poetry/core/masonry/utils/package_include.py#L47 😞
…#42) UserManager has a couple more methods
* Do not recomment using django-stubs-ext anymore, it is confusing since it was created for django-stubs itself * Add `ForeignKey` to the list of classes that needs to be patched * Improve documentation for `ForeignKey` and `RelatedManager` typing
We may need to loosen these, but as a default they should work pretty well. Previously we typed the global cache as `Any`, but `BaseCache` should work and has the various methods defined as well. sbdchd#46
With this change we should be able to get `Foo.objects` to return `Manager[Foo]` without having to manually type it.
Now that Kodiak is using the latest poetry using any of the other projects on the old version is a pain. So upgrade time!
Newer version of poetry handles system links differently breaking the build. related: sbdchd/celery-types#40
Django 3.1 updated these db deletion errors to show the set of all objects that protected/restricted the deletion, as opposed to just the model of one object. As such, these stubs need to be updated. This matches how these errors are typed in `typeddjango`.
This was built on top of #62, so merging it should only keep this PR's change
I do not know if there was a particular reason for why it was not implemented before. But, I took the liberty to mimic what was done for similar fields on the upstream. Essentially, The `__init__` was overloaded to distinguish between `null=True` and `null=False` to signal the resulting type, `Optional[date]` or `date` respectively.
This was built on top of sbdchd#63, so merging it should only keep this PR's change Note that even though the change looks big, it actually is pretty small, it is just that all fields need to define their own `__new__` (or `__init__` if their signature is different from the base field), and it is all the same, the difference is the classname and the generic field. I also added some documentation [here](https://github.com/sbdchd/django-types/pull/65/files#diff-876a5d116ef70c86039fbb8498623871324fa93fc1ae51c7c09ba2a0f7612e99R47) explaining the usage. Fix sbdchd#34
django/django#12405 (comment) QuerySet and BaseManager already have __class_getitem__, starting from Django 3.1
Closes sbdchd#75 Thanks!
Just upgraded to 0.11.0 and notice some errors on my migrations. There's no need to set covariant/contravariant on _GT/_ST. The tests are just there to make sure that there are no errors anymore. If the code is reverted the test would fail
I think that it was removed in one of the recent PRs for improving `ManyToManyField` typing.
…ny-to-many relationships. From the docs for `add()`: https://docs.djangoproject.com/en/4.0/ref/models/relations/#django.db.models.fields.related.RelatedManager.add > For many-to-many relationships add() accepts either model instances or field values, normally primary keys, as the *objs argument. Likewise for `remove()`: https://docs.djangoproject.com/en/4.0/ref/models/relations/#django.db.models.fields.related.RelatedManager.remove > For many-to-many relationships remove() accepts either model instances or field values, normally primary keys, as the *objs argument.
Whoa. Something is seriously messed up with this PR, my apologies. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
django-sources
#13)_default_manager
#17)ForeignKey
error:Invalid value for a to= parameter
withstr
value #28)objects
manager to django.contrib.auth.models.User (Remove _Val alias for MultiValueDict so that generic evaluate #36)