Skip to content

Commit 515f403

Browse files
committed
Add Import.implicit and .excluded methods for excluding known implicit modules.
Ref #8
1 parent 3a932a5 commit 515f403

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

imports.py

+21
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ def builtin(self):
9696
# for compatibility
9797
return self.standard()
9898

99+
def implicit(self):
100+
"""
101+
Is this module implicitly available (based on other conditions)?
102+
103+
For example, ``_typeshed`` is made available at runtime by mypy
104+
and other type checkers and will not have a distribution that
105+
supplies it.
106+
107+
>>> Import('_typeshed.StrPath').implicit()
108+
True
109+
>>> Import('._typeshed').implicit()
110+
False
111+
>>> Import('os').implicit()
112+
False
113+
"""
114+
implicit = {'_typeshed'}
115+
return self.top in implicit
116+
117+
def excluded(self):
118+
return self.implicit() or self.standard()
119+
99120
CPE = jaraco.context.ExceptionTrap(subprocess.CalledProcessError)
100121

101122
@staticmethod

0 commit comments

Comments
 (0)