Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a67d53

Browse files
committed
names imported with as but renamed to a private name are not exported
1 parent 10f3d57 commit 3a67d53

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

tests/test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def test_get_stub_names(self) -> None:
5656
names = get_stub_names('simple', version=(3, 5))
5757
self.assertEqual(set(names.keys()), {
5858
'var', 'old_var', 'func', 'async_func', 'Cls', '_private',
59-
'exported', 'unexported', 'other', 'multiple', 'assignment', 'new_name'
59+
'exported', 'unexported', 'other', 'multiple', 'assignment', 'new_name',
60+
'_made_private',
6061
})
6162

6263
# Simple assignments
@@ -76,6 +77,9 @@ def test_get_stub_names(self) -> None:
7677
self.assertEqual(names['unexported'].ast, typeshed_client.ImportedName(path, 'unexported'))
7778
self.check_nameinfo(names, 'new_name', typeshed_client.ImportedName)
7879
self.assertEqual(names['new_name'].ast, typeshed_client.ImportedName(path, 'renamed'))
80+
self.check_nameinfo(names, '_made_private', typeshed_client.ImportedName, is_exported=False)
81+
self.assertEqual(names['_made_private'].ast,
82+
typeshed_client.ImportedName(path, 'made_private'))
7983

8084
# Functions
8185
self.check_nameinfo(names, 'func', ast3.FunctionDef)

tests/typeshed/stdlib/3/other.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
unexported: int
22
exported: int
33
renamed: int
4+
made_private: int

tests/typeshed/stdlib/3/simple.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import other
2-
from other import unexported, exported as exported, renamed as new_name
2+
from other import unexported, exported as exported, renamed as new_name, made_private as _made_private
33

44
_private: int
55

typeshed_client/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def visit_ImportFrom(self, node: ast3.ImportFrom) -> Iterable[NameInfo]:
152152
source_module = ModulePath(self.module_name[:-node.level] + module)
153153
for alias in node.names:
154154
if alias.asname is not None:
155-
yield NameInfo(alias.asname, True, ImportedName(source_module, alias.name))
155+
is_exported = not alias.asname.startswith('_')
156+
yield NameInfo(alias.asname, is_exported, ImportedName(source_module, alias.name))
156157
else:
157158
yield NameInfo(alias.name, False, ImportedName(source_module, alias.name))
158159

0 commit comments

Comments
 (0)