Skip to content

Commit

Permalink
Capture that _get_toplevel_name can return None.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 18, 2023
1 parent 851b921 commit 1c4b328
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def _topmost(name: PackagePath) -> Optional[str]:
return top if rest else None


def _get_toplevel_name(name: PackagePath) -> str:
def _get_toplevel_name(name: PackagePath) -> Optional[str]:
"""
Infer a possibly importable module name from a name presumed on
sys.path.
Expand All @@ -992,6 +992,8 @@ def _get_toplevel_name(name: PackagePath) -> str:
'foo'
>>> _get_toplevel_name(PackagePath('foo/__init__.py'))
'foo'
>>> _get_toplevel_name(PackagePath('foo.pth'))
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
"""
return _topmost(name) or (
# python/typeshed#10328
Expand Down

0 comments on commit 1c4b328

Please sign in to comment.