forked from VimPlug/jedi
Have all py__file__ methods return a Path
This commit is contained in:
@@ -8,6 +8,8 @@ import warnings
|
|||||||
import re
|
import re
|
||||||
import builtins
|
import builtins
|
||||||
import typing
|
import typing
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from jedi.inference.compiled.getattr_static import getattr_static
|
from jedi.inference.compiled.getattr_static import getattr_static
|
||||||
|
|
||||||
@@ -179,9 +181,9 @@ class DirectObjectAccess:
|
|||||||
def py__bool__(self):
|
def py__bool__(self):
|
||||||
return bool(self._obj)
|
return bool(self._obj)
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
try:
|
try:
|
||||||
return self._obj.__file__
|
return Path(self._obj.__file__)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import re
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import Parameter
|
from inspect import Parameter
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.inference.utils import to_list
|
from jedi.inference.utils import to_list
|
||||||
@@ -305,11 +306,8 @@ class CompiledModule(CompiledValue):
|
|||||||
return ()
|
return ()
|
||||||
return tuple(name.split('.'))
|
return tuple(name.split('.'))
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
path = self.access_handle.py__file__()
|
return self.access_handle.py__file__() # type: ignore[no-any-return]
|
||||||
if path is None:
|
|
||||||
return None
|
|
||||||
return Path(path)
|
|
||||||
|
|
||||||
|
|
||||||
class CompiledName(AbstractNameDefinition):
|
class CompiledName(AbstractNameDefinition):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from parso.tree import search_ancestor
|
from parso.tree import search_ancestor
|
||||||
from parso.python.tree import Name
|
from parso.python.tree import Name
|
||||||
@@ -307,8 +309,8 @@ class FunctionContext(TreeContextMixin, ValueContext):
|
|||||||
|
|
||||||
|
|
||||||
class ModuleContext(TreeContextMixin, ValueContext):
|
class ModuleContext(TreeContextMixin, ValueContext):
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
return self._value.py__file__()
|
return self._value.py__file__() # type: ignore[no-any-return]
|
||||||
|
|
||||||
def get_filters(self, until_position=None, origin_scope=None):
|
def get_filters(self, until_position=None, origin_scope=None):
|
||||||
filters = self._value.get_filters(origin_scope)
|
filters = self._value.get_filters(origin_scope)
|
||||||
@@ -355,8 +357,8 @@ class NamespaceContext(TreeContextMixin, ValueContext):
|
|||||||
def string_names(self):
|
def string_names(self):
|
||||||
return self._value.string_names
|
return self._value.string_names
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
return self._value.py__file__()
|
return self._value.py__file__() # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
class ClassContext(TreeContextMixin, ValueContext):
|
class ClassContext(TreeContextMixin, ValueContext):
|
||||||
@@ -405,8 +407,8 @@ class CompiledModuleContext(CompiledContext):
|
|||||||
def string_names(self):
|
def string_names(self):
|
||||||
return self._value.string_names
|
return self._value.string_names
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
return self._value.py__file__()
|
return self._value.py__file__() # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
def _get_global_filters_for_name(context, name_or_none, position):
|
def _get_global_filters_for_name(context, name_or_none, position):
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from jedi.inference.cache import inference_state_method_cache
|
from jedi.inference.cache import inference_state_method_cache
|
||||||
from jedi.inference.filters import DictFilter
|
from jedi.inference.filters import DictFilter
|
||||||
from jedi.inference.names import ValueNameMixin, AbstractNameDefinition
|
from jedi.inference.names import ValueNameMixin, AbstractNameDefinition
|
||||||
@@ -41,7 +44,7 @@ class ImplicitNamespaceValue(Value, SubModuleDictMixin):
|
|||||||
string_name = self.py__package__()[-1]
|
string_name = self.py__package__()[-1]
|
||||||
return ImplicitNSName(self, string_name)
|
return ImplicitNSName(self, string_name)
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self) -> Optional[Path]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def py__package__(self):
|
def py__package__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user