Skip to content

Stubgen: normalize input paths when finding common parent directory for out files #8067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 18, 2020
6 changes: 3 additions & 3 deletions mypy/stubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def remove_misplaced_type_comments(source: Union[str, bytes]) -> Union[str, byte
def common_dir_prefix(paths: List[str]) -> str:
if not paths:
return '.'
cur = os.path.dirname(paths[0])
cur = os.path.dirname(os.path.normpath(paths[0]))
for path in paths[1:]:
while True:
path = os.path.dirname(path)
if (cur + '/').startswith(path + '/'):
path = os.path.dirname(os.path.normpath(path))
if (cur + os.sep).startswith(path + os.sep):
cur = path
break
return cur or '.'
24 changes: 23 additions & 1 deletion mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ def h():

assert_equal(remove_misplaced_type_comments(original), dest)

def test_common_dir_prefix(self) -> None:
@unittest.skipIf(sys.platform == 'win32',
'Tests building the paths common ancestor on *nix')
def test_common_dir_prefix_unix(self) -> None:
assert common_dir_prefix([]) == '.'
assert common_dir_prefix(['x.pyi']) == '.'
assert common_dir_prefix(['./x.pyi']) == '.'
Expand All @@ -458,6 +460,26 @@ def test_common_dir_prefix(self) -> None:
assert common_dir_prefix(['foo/x.pyi', 'foo/bar/zar/y.pyi']) == 'foo'
assert common_dir_prefix(['foo/bar/zar/x.pyi', 'foo/bar/y.pyi']) == 'foo/bar'
assert common_dir_prefix(['foo/bar/x.pyi', 'foo/bar/zar/y.pyi']) == 'foo/bar'
assert common_dir_prefix([r'foo/bar\x.pyi']) == 'foo'
assert common_dir_prefix([r'foo\bar/x.pyi']) == r'foo\bar'

@unittest.skipIf(sys.platform != 'win32',
'Tests building the paths common ancestor on Windows')
def test_common_dir_prefix_win(self) -> None:
assert common_dir_prefix(['x.pyi']) == '.'
assert common_dir_prefix([r'.\x.pyi']) == '.'
assert common_dir_prefix([r'foo\bar\x.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo\bar\x.pyi',
r'foo\bar\y.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo\bar\x.pyi', r'foo\y.pyi']) == 'foo'
assert common_dir_prefix([r'foo\x.pyi', r'foo\bar\y.pyi']) == 'foo'
assert common_dir_prefix([r'foo\bar\zar\x.pyi', r'foo\y.pyi']) == 'foo'
assert common_dir_prefix([r'foo\x.pyi', r'foo\bar\zar\y.pyi']) == 'foo'
assert common_dir_prefix([r'foo\bar\zar\x.pyi', r'foo\bar\y.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo\bar\x.pyi', r'foo\bar\zar\y.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo/bar\x.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo\bar/x.pyi']) == r'foo\bar'
assert common_dir_prefix([r'foo/bar/x.pyi']) == r'foo\bar'


class StubgenHelpersSuite(unittest.TestCase):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy