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

Only build the fancy docstring when in an IPython context #774

Merged
merged 1 commit into from Jul 24, 2023

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jun 28, 2023

I was a little surprised to see that Param was always building a docstring for IPython even not in an IPython context. This also came with some side-effects as the pager calls .param.objects() which leads to the Parameters being cached on the class:

params = dict(obj.param.objects('existing'))

This can only improve the performance of loading modules with lots of Parameterized classes that have lots of Parameters, no idea by how much though!

However, this of course also affects how the docstring look like in a non IPython context, e.g. in the Python REPL.

Before (colorized output):

>>> import param
>>> class P(param.Parameterized):
...   """The class docstring"""
...   x = param.Parameter()
... 
>>> p = P()
>>> print(p.__doc__)
params(x=Parameter, name=String)
The class docstring
Parameters of 'P'
=================

Parameters changed from their default values are marked in red.
Soft bound values are marked in cyan.
C/V= Constant/Variable, RO/RW = ReadOnly/ReadWrite, AN=Allow None

NameValue     Type      Mode  

x   None  Parameter  V RW AN 

Parameter docstrings:
=====================

x: < No docstring available >

With this change:

>>> import param
>>> class P(param.Parameterized):
...   """The class docstring"""
...   x = param.Parameter()
... 
>>> p = P()
>>> print(p.__doc__)
params(x=Parameter, name=String)
The class docstring

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

Sounds like a good idea!

@maximlt maximlt merged commit 00a5b85 into main Jul 24, 2023
10 checks passed
@maximlt maximlt deleted the check_ipython branch July 24, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants