Skip to content

Commit

Permalink
Extracted Import.top property.
Browse files Browse the repository at this point in the history
Now a name is not checked for stdlib relevance if it's relative.

Ref #8.
  • Loading branch information
jaraco committed Sep 21, 2024
1 parent f7a547d commit 3a932a5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,23 @@ def standard(self):
True
>>> Import('pip').standard()
False
>>> Import('.os').standard()
False
"""
return bool(self.top) and self._check_standard(self.top)

@property
def top(self) -> str | None:
"""
Return the top-level name for this import.
>>> Import('foo.bar').top
'foo'
>>> Import('foo').top
'foo'
>>> Import('.foo.bar').top
"""
return self._check_standard(self.split('.')[0])
return self.split('.')[0] or None

def builtin(self):
# for compatibility
Expand Down

0 comments on commit 3a932a5

Please sign in to comment.