diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index a94e9a5..b9cee99 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1445,8 +1445,20 @@ class InteractiveShell(SingletonConfigurable): ismagic = True isalias = isinstance(obj, Alias) - return {'found':found, 'obj':obj, 'namespace':ospace, - 'ismagic':ismagic, 'isalias':isalias, 'parent':parent} + # Last try: special-case some literals like '', [], {}, etc: + if not found and oname_head in ["''",'""','[]','{}','()']: + obj = eval(oname_head) + found = True + ospace = 'Interactive' + + return { + 'obj':obj, + 'found':found, + 'parent':parent, + 'ismagic':ismagic, + 'isalias':isalias, + 'namespace':ospace + } @staticmethod def _getattr_property(obj, attrname): @@ -2550,7 +2562,7 @@ class InteractiveShell(SingletonConfigurable): where.update( runpy.run_module(str(mod_name), run_name="__main__", alter_sys=True) - ) + ) except SystemExit as status: if status.code: raise diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index b3021f1..3a2e3f9 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -587,7 +587,21 @@ class Inspector(Colorable): return bundle def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): - """Retrieve an info dict and format it.""" + """Retrieve an info dict and format it. + + Parameters + ========== + + obj: any + Object to inspect and return info from + oname: str (default: ''): + Name of the variable pointing to `obj`. + formatter: callable + info: + already computed informations + detail_level: integer + Granularity of detail level, if set to 1, give more informations. + """ info = self._info(obj, oname=oname, info=info, detail_level=detail_level) @@ -696,24 +710,31 @@ class Inspector(Colorable): DeprecationWarning, stacklevel=2) return self._info(obj, oname=oname, info=info, detail_level=detail_level) - def _info(self, obj, oname='', info=None, detail_level=0): + def _info(self, obj, oname='', info=None, detail_level=0) -> dict: """Compute a dict with detailed information about an object. - Optional arguments: - - - oname: name of the variable pointing to the object. - - - info: a structure with some information fields which may have been - precomputed already. - - - detail_level: if set to 1, more information is given. + Parameters + ========== + + obj: any + An object to find information about + oname: str (default: ''): + Name of the variable pointing to `obj`. + info: (default: None) + A struct (dict like with attr access) with some information fields + which may have been precomputed already. + detail_level: int (default:0) + If set to 1, more information is given. + + Returns + ======= + + An object info dict with known fields from `info_fields`. """ - obj_type = type(obj) - if info is None: - ismagic = 0 - isalias = 0 + ismagic = False + isalias = False ospace = '' else: ismagic = info.ismagic @@ -743,17 +764,17 @@ class Inspector(Colorable): shalf = int((string_max - 5) / 2) if ismagic: - obj_type_name = 'Magic function' + out['type_name'] = 'Magic function' elif isalias: - obj_type_name = 'System alias' + out['type_name'] = 'System alias' else: - obj_type_name = obj_type.__name__ - out['type_name'] = obj_type_name + out['type_name'] = type(obj).__name__ try: bclass = obj.__class__ out['base_class'] = str(bclass) - except: pass + except: + pass # String form, but snip if too long in ? form (full in ??) if detail_level >= self.str_detail_level: @@ -774,7 +795,8 @@ class Inspector(Colorable): # Length (for strings and lists) try: out['length'] = str(len(obj)) - except: pass + except Exception: + pass # Filename where object was defined binary_file = False