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

Add json option to lsmagic #14331

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
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
10 changes: 9 additions & 1 deletion IPython/core/magics/basic.py
Expand Up @@ -176,10 +176,18 @@ def alias_magic(self, line=''):
magic_escapes['cell'], name,
magic_escapes['cell'], target, params_str))

@magic_arguments.magic_arguments()
@magic_arguments.argument(
"-j", "--json", action="store_true", help="Output as JSON"
)
@line_magic
def lsmagic(self, parameter_s=''):
"""List currently available magic functions."""
return MagicsDisplay(self.shell.magics_manager, ignore=[])
args = magic_arguments.parse_argstring(self.lsmagic, parameter_s)
md = MagicsDisplay(self.shell.magics_manager, ignore=[])
if args.json:
return md._repr_json_()
return md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a simple either/or, I would suggest the slightly more immediately explicit

if args.json:
    return md._repr_json_()
else:
    return md

But otherwise looks good to me.

Thanks!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fperez
Thanks, for your review.
I modified at 36a3759


def _magic_docs(self, brief=False, rest=False):
"""Return docstrings from magic functions."""
Expand Down