Source code for bokeh.util.functions
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2022, Anaconda, Inc., and Bokeh Contributors.
# All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
''' Utilities for function introspection.
'''
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import annotations
import logging # isort:skip
log = logging.getLogger(__name__)
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Standard library imports
from typing import (
TYPE_CHECKING,
Any,
List,
Tuple,
)
if TYPE_CHECKING:
from inspect import Signature
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
__all__ = (
'get_param_info',
)
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
[docs]def get_param_info(sig: Signature) -> Tuple[List[str], List[Any]]:
''' Find parameters with defaults and return them.
Arguments:
sig (Signature) : a function signature
Returns:
tuple(list, list) : parameters with defaults
'''
defaults = []
for param in sig.parameters.values():
if param.default is not param.empty:
defaults.append(param.default)
return [name for name in sig.parameters], defaults