Skip to content

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
@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.

2 participants