mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 01:38:36 +08:00
Implement all remaining Path issues and use it instead of strings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from jedi.inference.gradual.typeshed import TYPESHED_PATH, create_stub_module
|
||||
|
||||
@@ -9,14 +10,18 @@ def load_proper_stub_module(inference_state, file_io, import_names, module_node)
|
||||
module.
|
||||
"""
|
||||
path = file_io.path
|
||||
assert path.endswith('.pyi')
|
||||
if path.startswith(TYPESHED_PATH):
|
||||
# /foo/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
|
||||
rest = path[len(TYPESHED_PATH) + 1: -4]
|
||||
split_paths = tuple(rest.split(os.path.sep))
|
||||
path = Path(path)
|
||||
assert path.suffix == '.pyi'
|
||||
try:
|
||||
relative_path = path.relative_to(TYPESHED_PATH)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
# /[...]/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
|
||||
rest = relative_path.with_suffix('')
|
||||
# Remove the stdlib/3 or third_party/3.6 part
|
||||
import_names = split_paths[2:]
|
||||
if import_names[-1] == '__init__':
|
||||
import_names = rest.parts[2:]
|
||||
if rest.name == '__init__':
|
||||
import_names = import_names[:-1]
|
||||
|
||||
if import_names is not None:
|
||||
|
||||
Reference in New Issue
Block a user