]> crepu.dev Git - config.git/blame - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/jedi/inference/gradual/utils.py
ActualizaciĆ³n de Readme
[config.git] / djavu-asus / elpy / rpc-venv / lib / python3.11 / site-packages / jedi / inference / gradual / utils.py
CommitLineData
53e6db90
DC
1from pathlib import Path
2
3from jedi.inference.gradual.typeshed import TYPESHED_PATH, create_stub_module
4
5
6def load_proper_stub_module(inference_state, grammar, file_io, import_names, module_node):
7 """
8 This function is given a random .pyi file and should return the proper
9 module.
10 """
11 path = file_io.path
12 path = Path(path)
13 assert path.suffix == '.pyi'
14 try:
15 relative_path = path.relative_to(TYPESHED_PATH)
16 except ValueError:
17 pass
18 else:
19 # /[...]/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
20 rest = relative_path.with_suffix('')
21 # Remove the stdlib/3 or third_party/3.6 part
22 import_names = rest.parts[2:]
23 if rest.name == '__init__':
24 import_names = import_names[:-1]
25
26 if import_names is not None:
27 actual_value_set = inference_state.import_module(import_names, prefer_stubs=False)
28
29 stub = create_stub_module(
30 inference_state, grammar, actual_value_set,
31 module_node, file_io, import_names
32 )
33 inference_state.stub_module_cache[import_names] = stub
34 return stub
35 return None