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

perf: Only update Parameter signatures when needed #1038

Merged
merged 7 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion param/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def exceptions_summarized():

def _in_ipython():
try:
get_ipython()
get_ipython
return True
except NameError:
return False
Expand Down
6 changes: 6 additions & 0 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import numbers
import operator
import os
import re
import sys
import types
Expand Down Expand Up @@ -981,6 +982,9 @@ def __getattribute__(mcs,name):
return type.__getattribute__(mcs,name)


_UDPATE_PARAM_SIGNATURE = _in_ipython() or (os.getenv("PARAM_PARAMETER_SIGNATURE", "false").lower() in ("1" , "true"))


class _ParameterBase(metaclass=ParameterMetaclass):
"""
Base Parameter class used to dynamically update the signature of all
Expand All @@ -996,6 +1000,8 @@ def _modified_slots_defaults(cls):
@classmethod
def __init_subclass__(cls):
super().__init_subclass__()
if not _UDPATE_PARAMETER_SIGNATURE:
return
# _update_signature has been tested against the Parameters available
# in Param, we don't want to break the Parameters created elsewhere
# so wrapping this in a loose try/except.
Expand Down
3 changes: 3 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ nbval = "*"
[feature.doc]
channels = ["pyviz"]

[feature.doc.activation.env]
PARAM_PARAMETER_SIGNATURE = "1"

[feature.doc.dependencies]
graphviz = "*"
nbsite = ">=0.8.4,<0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ asyncio_mode = "auto"
asyncio_default_fixture_loop_scope="function"

[tool.coverage.report]
omit = ["param/version.py"]
omit = ["param/version.py", "tests/testimports.py"]
Copy link
Member Author

Choose a reason for hiding this comment

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

This belongs to the other PR, but I don't think moving it over to it is important.


[tool.ruff]
fix = true
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os

os.environ["PARAM_PARAMETER_SIGNATURE"] = "1" # To force signature in _ParameterBase.__init_subclass__

import param
import pytest

Expand Down
Loading