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

Skip to content

Commit 22fe0a8

Browse files
committed
ensure __all__ and __dir__ are defined on shims
require from `from shim import *` to work properly
1 parent 1cca72b commit 22fe0a8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

IPython/utils/shimmodule.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ def __path__(self):
6868
def __spec__(self):
6969
"""Don't produce __spec__ until requested"""
7070
return __import__(self._mirror).__spec__
71+
72+
def __dir__(self):
73+
return dir(__import__(self._mirror))
74+
75+
@property
76+
def __all__(self):
77+
"""Ensure __all__ is always defined"""
78+
mod = __import__(self._mirror)
79+
try:
80+
return mod.__all__
81+
except AttributeError:
82+
return [name for name in dir(mod) if not name.startswith('_')]
7183

7284
def __getattr__(self, key):
7385
# Use the equivalent of import_item(name), see below

0 commit comments

Comments
 (0)