mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-11 22:41:55 +08:00
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import configparser
|
||||
import sys
|
||||
from functools import partial
|
||||
from typing import Callable, Dict, List, NoReturn, Optional, Tuple, cast
|
||||
|
||||
from django.db.models.fields.related import RelatedField
|
||||
from mypy.modulefinder import mypy_path
|
||||
from mypy.nodes import MypyFile, TypeInfo
|
||||
from mypy.options import Options
|
||||
from mypy.plugin import (
|
||||
@@ -91,6 +93,10 @@ class NewSemanalDjangoPlugin(Plugin):
|
||||
def __init__(self, options: Options) -> None:
|
||||
super().__init__(options)
|
||||
django_settings_module = extract_django_settings_module(options.config_file)
|
||||
# Add paths from MYPYPATH env var
|
||||
sys.path.extend(mypy_path())
|
||||
# Add paths from mypy_path config option
|
||||
sys.path.extend(options.mypy_path)
|
||||
self.django_context = DjangoContext(django_settings_module)
|
||||
|
||||
def _get_current_queryset_bases(self) -> Dict[str, int]:
|
||||
|
||||
@@ -38,3 +38,30 @@
|
||||
class MyModel(models.Model):
|
||||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
|
||||
- case: add_mypy_path_to_package_search
|
||||
main: |
|
||||
import extra_module
|
||||
mypy_config: |
|
||||
[mypy]
|
||||
mypy_path = ./extras
|
||||
[mypy.plugins.django-stubs]
|
||||
django_settings_module = mysettings
|
||||
files:
|
||||
- path: extras/extra_module.py
|
||||
content: |
|
||||
def extra_fn():
|
||||
pass
|
||||
|
||||
- case: add_mypypath_env_var_to_package_search
|
||||
main: |
|
||||
import extra_module
|
||||
mypy_config: |
|
||||
[mypy.plugins.django-stubs]
|
||||
django_settings_module = mysettings
|
||||
env:
|
||||
- MYPYPATH=./extras
|
||||
files:
|
||||
- path: extras/extra_module.py
|
||||
content: |
|
||||
def extra_fn():
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user