mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-20 10:51:16 +08:00
create monkeypatching function for adding get_item dunder (#526)
* run black * create monkeypatching function for adding get_item dunder * whoops i forgot the test * change the name in INSTALLED_APPS to make test pass * turn the whole thing into a proper package * move django_stubs_ext to requirements.txt * also install requirements.txt * attempt to fix pre-commit * numerous small code review fixes * fix dependency issues * small dependency fixes * configure proper license file location * add the rest of the monkeypatching * use strict mypy * update contributing with a note monkeypatching generics * copy release script from parent package
This commit is contained in:
49
django_stubs_ext/README.md
Normal file
49
django_stubs_ext/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Extensions and monkey-patching for django-stubs
|
||||
|
||||
[](https://travis-ci.com/typeddjango/django-stubs)
|
||||
[](http://mypy-lang.org/)
|
||||
[](https://gitter.im/mypy-django/Lobby)
|
||||
|
||||
|
||||
This package contains extensions and monkey-patching functions for the [django-stubs](https://github.com/typeddjango/django-stubs) package. Certain features of django-stubs (i.e. generic django classes that don't define the `__class_getitem__` method) require runtime monkey-patching, which can't be done with type stubs. These extensions were split into a separate package so library consumers don't need `mypy` as a runtime dependency ([#526](https://github.com/typeddjango/django-stubs/pull/526#pullrequestreview-525798031)).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install django-stubs-ext
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In your Django application, use the following code:
|
||||
|
||||
```py
|
||||
import django_stubs_ext
|
||||
|
||||
django_stubs_ext.monkeypath()
|
||||
```
|
||||
|
||||
This only needs to be called once, so the call to `monkeypatch` should be placed in your top-level urlconf.
|
||||
|
||||
## Version compatibility
|
||||
|
||||
Since django-stubs supports multiple Django versions, this package takes care to only monkey-patch the features needed by your django version, and decides which features to patch at runtime. This is completely safe, as (currently) we only add a `__class_getitem__` method that does nothing:
|
||||
|
||||
```py
|
||||
@classmethod
|
||||
def __class_getitem__(cls, *args, **kwargs):
|
||||
return cls
|
||||
```
|
||||
|
||||
## To get help
|
||||
|
||||
For help with django-stubs, please view the main repository at <https://github.com/typeddjango/django-stubs>
|
||||
|
||||
We have a Gitter chat here: <https://gitter.im/mypy-django/Lobby>
|
||||
If you think you have a more generic typing issue, please refer to <https://github.com/python/mypy> and their Gitter.
|
||||
|
||||
## Contributing
|
||||
|
||||
The django-stubs-ext package is part of the [django-stubs](https://github.com/typeddjango/django-stubs) monorepo. If you would like to contribute, please view the django-stubs [contribution guide](https://github.com/typeddjango/django-stubs/blob/master/CONTRIBUTING.md).
|
||||
|
||||
You can always also reach out in gitter to discuss your contributions!
|
||||
Reference in New Issue
Block a user