mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-20 04:21:13 +08:00
Include Django stubs as a third party repo
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
|||||||
[submodule "jedi/third_party/typeshed"]
|
[submodule "jedi/third_party/typeshed"]
|
||||||
path = jedi/third_party/typeshed
|
path = jedi/third_party/typeshed
|
||||||
url = https://github.com/davidhalter/typeshed.git
|
url = https://github.com/davidhalter/typeshed.git
|
||||||
|
[submodule "jedi/third_party/django-stubs"]
|
||||||
|
path = jedi/third_party/django-stubs
|
||||||
|
url = https://github.com/typeddjango/django-stubs
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ from jedi.inference.value import ModuleValue
|
|||||||
|
|
||||||
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
||||||
|
DJANGO_INIT_PATH = os.path.join(_jedi_path, 'third_party', 'django-stubs',
|
||||||
|
'django-stubs', '__init__.pyi')
|
||||||
|
|
||||||
_IMPORT_MAP = dict(
|
_IMPORT_MAP = dict(
|
||||||
_collections='collections',
|
_collections='collections',
|
||||||
@@ -173,6 +175,13 @@ def _try_to_load_stub(inference_state, import_names, python_value_set,
|
|||||||
)
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
if import_names[0] == 'django':
|
||||||
|
return _try_to_load_stub_from_file(
|
||||||
|
inference_state,
|
||||||
|
python_value_set,
|
||||||
|
file_io=FileIO(DJANGO_INIT_PATH),
|
||||||
|
import_names=import_names,
|
||||||
|
)
|
||||||
|
|
||||||
# 2. Try to load pyi files next to py files.
|
# 2. Try to load pyi files next to py files.
|
||||||
for c in python_value_set:
|
for c in python_value_set:
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ from jedi.inference.base_value import ValueSet
|
|||||||
from jedi.inference.filters import ParserTreeFilter, DictFilter
|
from jedi.inference.filters import ParserTreeFilter, DictFilter
|
||||||
from jedi.inference.names import NameWrapper
|
from jedi.inference.names import NameWrapper
|
||||||
from jedi.inference.value.instance import TreeInstance
|
from jedi.inference.value.instance import TreeInstance
|
||||||
|
from jedi.inference.gradual.base import GenericClass
|
||||||
|
from jedi.inference.gradual.generics import TupleGenericManager
|
||||||
|
|
||||||
|
|
||||||
mapping = {
|
mapping = {
|
||||||
@@ -83,12 +85,28 @@ class DjangoModelName(NameWrapper):
|
|||||||
return _infer_field(self._cls, self._wrapped_name)
|
return _infer_field(self._cls, self._wrapped_name)
|
||||||
|
|
||||||
|
|
||||||
|
def _create_manager_for(cls):
|
||||||
|
managers = cls.inference_state.import_module(
|
||||||
|
('django', 'db', 'models', 'manager')
|
||||||
|
).py__getattribute__('BaseManager')
|
||||||
|
for m in managers:
|
||||||
|
if m.is_class() and not m.is_compiled():
|
||||||
|
generics_manager = TupleGenericManager((ValueSet([cls]),))
|
||||||
|
for c in GenericClass(m, generics_manager).execute_annotation():
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _new_dict_filter(cls):
|
def _new_dict_filter(cls):
|
||||||
filter_ = ParserTreeFilter(parent_context=cls.as_context())
|
filter_ = ParserTreeFilter(parent_context=cls.as_context())
|
||||||
return DictFilter({
|
dct = {
|
||||||
name.string_name: DjangoModelName(cls, name)
|
name.string_name: DjangoModelName(cls, name)
|
||||||
for name in filter_.values()
|
for name in filter_.values()
|
||||||
})
|
}
|
||||||
|
manager = _create_manager_for(cls)
|
||||||
|
if manager:
|
||||||
|
dct['objects'] = manager.name
|
||||||
|
return DictFilter(dct)
|
||||||
|
|
||||||
|
|
||||||
def get_metaclass_filters(func):
|
def get_metaclass_filters(func):
|
||||||
|
|||||||
1
jedi/third_party/django-stubs
vendored
Submodule
1
jedi/third_party/django-stubs
vendored
Submodule
Submodule jedi/third_party/django-stubs added at 92c8dfc93f
@@ -105,3 +105,14 @@ model_instance.tags_m2m
|
|||||||
model_instance.unidentifiable
|
model_instance.unidentifiable
|
||||||
#! ['unidentifiable = NOT_FOUND']
|
#! ['unidentifiable = NOT_FOUND']
|
||||||
model_instance.unidentifiable
|
model_instance.unidentifiable
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# Queries
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
#? models.query.QuerySet.filter
|
||||||
|
model_instance.objects.filter
|
||||||
|
#? BusinessModel() None
|
||||||
|
model_instance.objects.filter().first()
|
||||||
|
#? str()
|
||||||
|
model_instance.objects.get().char_field
|
||||||
|
|||||||
Reference in New Issue
Block a user