Skip to content

Commit

Permalink
perf: Only update Parameter signatures when needed (#1038)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxime Liquet <[email protected]>
  • Loading branch information
hoxbro and maximlt authored Feb 27, 2025
1 parent 9a8dcce commit 803e650
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion param/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,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 @@ -13,6 +13,7 @@
import inspect
import numbers
import operator
import os
import re
import sys
import types
Expand Down Expand Up @@ -982,6 +983,9 @@ def __getattribute__(mcs,name):
return type.__getattribute__(mcs,name)


_UDPATE_PARAMETER_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 @@ -997,6 +1001,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"]

[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

0 comments on commit 803e650

Please sign in to comment.