1 from pathlib
import Path
2 from typing
import Optional
4 from jedi
.inference
.cache
import inference_state_method_cache
5 from jedi
.inference
.filters
import DictFilter
6 from jedi
.inference
.names
import ValueNameMixin
, AbstractNameDefinition
7 from jedi
.inference
.base_value
import Value
8 from jedi
.inference
.value
.module
import SubModuleDictMixin
9 from jedi
.inference
.context
import NamespaceContext
12 class ImplicitNSName(ValueNameMixin
, AbstractNameDefinition
):
14 Accessing names for implicit namespace packages should infer to nothing.
15 This object will prevent Jedi from raising exceptions
17 def __init__(self
, implicit_ns_value
, string_name
):
18 self
._value
= implicit_ns_value
19 self
.string_name
= string_name
22 class ImplicitNamespaceValue(Value
, SubModuleDictMixin
):
24 Provides support for implicit namespace packages
26 api_type
= 'namespace'
29 def __init__(self
, inference_state
, string_names
, paths
):
30 super().__init
__(inference_state
, parent_context
=None)
31 self
.inference_state
= inference_state
32 self
.string_names
= string_names
35 def get_filters(self
, origin_scope
=None):
36 yield DictFilter(self
.sub_modules_dict())
38 def get_qualified_names(self
):
41 @property # type: ignore[misc]
42 @inference_state_method_cache()
44 string_name
= self
.py__package__()[-1]
45 return ImplicitNSName(self
, string_name
)
47 def py__file__(self
) -> Optional
[Path
]:
50 def py__package__(self
):
51 """Return the fullname
53 return self
.string_names
59 return '.'.join(self
.string_names
)
61 def is_namespace(self
):
71 return NamespaceContext(self
)
74 return '<%s: %s>' % (self
.__class
__.__name
__, self
.py__name__())