Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictable and safe object inspection #13833

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dbdf10a
Add Google Colab's oinspect module (Apache 2.0 licensed) for a safe v…
jasongrout Nov 17, 2022
2606566
Format with darker to conform to ipython conventions
jasongrout Nov 17, 2022
c6d9c20
Modify class names to be more generic and add more context and proven…
jasongrout Nov 17, 2022
254e458
Use ast.unparse (Python 3.9+) instead of astor to generate Python cod…
jasongrout Nov 17, 2022
6444cc7
Remove the obsolete formatter argument to info() (removed in IPython …
jasongrout Nov 17, 2022
16dd44b
Populate the subclasses attribute, required in how current IPython us…
jasongrout Nov 17, 2022
a474947
Make inspector class a configurable attribute in InteractiveShell.
jasongrout Nov 17, 2022
47dc82a
Make oinspect._render_signature code more closely align with the upst…
jasongrout Nov 18, 2022
77de2d9
Update SafeInspector._getdef to more closely align with Inspector._ge…
jasongrout Nov 18, 2022
1890711
Simplify oinspect.getdoc, should be no change in behavior.
jasongrout Nov 19, 2022
865f99a
Better oinspect docstring
jasongrout Nov 19, 2022
35d573f
Simplify getting defaults in oinspect info()
jasongrout Nov 19, 2022
dff3b93
Reorganize first part of oinspect info()
jasongrout Nov 19, 2022
2ff4b22
Add source_start_line and source_end_line fields to oinspect info inf…
jasongrout Nov 19, 2022
5ec46af
Add the isclass field as True/False always (instead of True/None)
jasongrout Nov 19, 2022
2777633
Simplify oinspect info: _getdef already catches any possible errors, …
jasongrout Nov 19, 2022
19e0540
Simplify oinspect info class docstring/definition code.
jasongrout Nov 19, 2022
4aa8a55
Simplify oinspect info: rename variables to make them more explicit
jasongrout Nov 19, 2022
b20fa3c
Simplify oinspect info getting class docstrings
jasongrout Nov 19, 2022
9d28937
Use inspect.unwrap to implement oinspect _get_wrapped
jasongrout Nov 19, 2022
997ec36
Simplify safeinspect
jasongrout Nov 19, 2022
a713132
Update oinspect unwrap method to never raise an error
jasongrout Nov 19, 2022
ea92cc1
Simplify safe inspect by deleting the info() method, instead implemen…
jasongrout Nov 19, 2022
c9e83ca
Fix indentation error
jasongrout Nov 19, 2022
ecd7f78
Run darker on oinspect and oinspect_safe
jasongrout Nov 19, 2022
8426ecc
import undoc in safe oinspect
jasongrout Nov 19, 2022
0cf2123
fix find_source_lines typo
jasongrout Nov 19, 2022
173b1d7
Sometimes find_source_lines may throw an exception, so guard against it
jasongrout Nov 20, 2022
42a2913
Fix typo in defaults
jasongrout Nov 20, 2022
edf572c
Copy parts of CPython's 3.11 inspect.py in order to modify the signat…
jasongrout Nov 21, 2022
5bee696
Modify our copy of parts of CPython's inspect.py from Python 3.11 to …
jasongrout Nov 21, 2022
75ea7d6
Update oinspect_safe to use the oinspect_safe_signature module methods
jasongrout Nov 21, 2022
67db7d9
Parametrize inspector tests to run with both inspectors
jasongrout Nov 22, 2022
f23afae
Delete obsolete comment
jasongrout Nov 22, 2022
e2366c0
Refactor safe_repr and start using it in the safe_signature file
jasongrout Nov 22, 2022
a68509b
Lint
jasongrout Nov 22, 2022
a4106bd
Move black config to pyproject.toml and update to exclude oinspect_sa…
jasongrout Nov 22, 2022
09d1ad2
Fix test setup and doc error
jasongrout Nov 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ def _import_runner(self, proposal):
displayhook_class = Type(DisplayHook)
display_pub_class = Type(DisplayPublisher)
compiler_class = Type(CachingCompiler)
inspector_class = Type(
oinspect.Inspector, help="Class to use to instantiate the shell inspector"
).tag(config=True)

sphinxify_docstring = Bool(False, help=
"""
Expand Down Expand Up @@ -755,10 +758,12 @@ def init_builtins(self):
@observe('colors')
def init_inspector(self, changes=None):
# Object inspector
self.inspector = oinspect.Inspector(oinspect.InspectColors,
PyColorize.ANSICodeColors,
self.colors,
self.object_info_string_level)
self.inspector = self.inspector_class(
oinspect.InspectColors,
PyColorize.ANSICodeColors,
self.colors,
self.object_info_string_level,
)

def init_io(self):
# implemented in subclasses, TerminalInteractiveShell does call
Expand Down