mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
add default for MYPY_DJANGO_CONFIG
This commit is contained in:
@@ -26,7 +26,7 @@ in your `mypy.ini` file.
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
In order to specify config file, set `MYPY_DJANGO_CONFIG` environment variable with path to the config file.
|
In order to specify config file, set `MYPY_DJANGO_CONFIG` environment variable with path to the config file. Default is `./mypy_django.ini`
|
||||||
|
|
||||||
Config file format (.ini):
|
Config file format (.ini):
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ class DjangoPlugin(Plugin):
|
|||||||
monkeypatch.restore_original_load_graph()
|
monkeypatch.restore_original_load_graph()
|
||||||
monkeypatch.restore_original_dependencies_handling()
|
monkeypatch.restore_original_dependencies_handling()
|
||||||
|
|
||||||
config_fpath = os.environ.get('MYPY_DJANGO_CONFIG')
|
config_fpath = os.environ.get('MYPY_DJANGO_CONFIG', 'mypy_django.ini')
|
||||||
if config_fpath:
|
if config_fpath and os.path.exists(config_fpath):
|
||||||
self.config = Config.from_config_file(config_fpath)
|
self.config = Config.from_config_file(config_fpath)
|
||||||
self.django_settings = self.config.django_settings_module
|
self.django_settings = self.config.django_settings_module
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -21,3 +21,15 @@ django_settings = mysettings
|
|||||||
[file mysettings.py]
|
[file mysettings.py]
|
||||||
MY_SETTING: int = 1
|
MY_SETTING: int = 1
|
||||||
[out]
|
[out]
|
||||||
|
|
||||||
|
[CASE mypy_django_ini_in_current_directory_is_a_default]
|
||||||
|
from django.conf import settings
|
||||||
|
reveal_type(settings.MY_SETTING) # E: Revealed type is 'builtins.int'
|
||||||
|
|
||||||
|
[file mypy_django.ini]
|
||||||
|
[[mypy_django_plugin]
|
||||||
|
django_settings = mysettings
|
||||||
|
|
||||||
|
[file mysettings.py]
|
||||||
|
MY_SETTING: int = 1
|
||||||
|
[out]
|
||||||
|
|||||||
Reference in New Issue
Block a user