Implement all remaining Path issues and use it instead of strings

This commit is contained in:
Dave Halter
2020-07-12 01:14:00 +02:00
parent db0e90763b
commit 480a464179
23 changed files with 131 additions and 97 deletions

View File

@@ -87,4 +87,4 @@ def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
assert has_python == (not d.is_stub())
assert d.full_name == full_name
assert d.is_stub() == d.module_path.endswith('.pyi')
assert d.is_stub() == (d.module_path.suffix == '.pyi')

View File

@@ -14,7 +14,7 @@ TYPESHED_PYTHON3 = os.path.join(typeshed.TYPESHED_PATH, 'stdlib', '3')
def test_get_typeshed_directories():
def get_dirs(version_info):
return {
p.path.replace(typeshed.TYPESHED_PATH, '').lstrip(os.path.sep)
p.path.replace(str(typeshed.TYPESHED_PATH), '').lstrip(os.path.sep)
for p in typeshed._get_typeshed_directories(version_info)
}
@@ -52,7 +52,7 @@ def test_keywords_variable(Script):
assert seq.name == 'Sequence'
# This points towards the typeshed implementation
stub_seq, = seq.goto(only_stubs=True)
assert typeshed.TYPESHED_PATH in stub_seq.module_path
assert str(stub_seq.module_path).startswith(str(typeshed.TYPESHED_PATH))
def test_class(Script):
@@ -91,8 +91,12 @@ def test_sys_exc_info(Script):
none, def_ = Script(code + '[1]').infer()
# It's an optional.
assert def_.name == 'BaseException'
assert def_.module_path == typeshed.TYPESHED_PATH.joinpath(
'stdlib', '2and3', 'builtins.pyi'
)
assert def_.type == 'instance'
assert none.name == 'NoneType'
assert none.module_path is None
none, def_ = Script(code + '[0]').infer()
assert def_.name == 'BaseException'
@@ -111,7 +115,7 @@ def test_sys_hexversion(Script):
script = Script('import sys; sys.hexversion')
def_, = script.complete()
assert isinstance(def_._name, StubName), def_._name
assert typeshed.TYPESHED_PATH in def_.module_path
assert str(def_.module_path).startswith(str(typeshed.TYPESHED_PATH))
def_, = script.infer()
assert def_.name == 'int'
@@ -138,14 +142,14 @@ def test_type_var(Script):
def test_math_is_stub(Script, code, full_name):
s = Script(code)
cos, = s.infer()
wanted = os.path.join('typeshed', 'stdlib', '2and3', 'math.pyi')
assert cos.module_path.endswith(wanted)
wanted = ('typeshed', 'stdlib', '2and3', 'math.pyi')
assert cos.module_path.parts[-4:] == wanted
assert cos.is_stub() is True
assert cos.goto(only_stubs=True) == [cos]
assert cos.full_name == full_name
cos, = s.goto()
assert cos.module_path.endswith(wanted)
assert cos.module_path.parts[-4:] == wanted
assert cos.goto(only_stubs=True) == [cos]
assert cos.is_stub() is True
assert cos.full_name == full_name