MCPcopy Create free account
hub / github.com/NanoComp/meep / filter_dict

Function filter_dict

python/visualization.py:106–123  ·  view source on GitHub ↗
(dict_to_filter: dict, func_with_kwargs: Callable)

Source from the content-addressed store, hash-verified

104# function (func_with_kwargs.)
105# Adapted from https://stackoverflow.com/questions/26515595/how-does-one-ignore-unexpected-keyword-arguments-passed-to-a-function/44052550
106def filter_dict(dict_to_filter: dict, func_with_kwargs: Callable) -> dict:
107 import inspect
108
109 filter_keys = []
110 try:
111 # Python3 ...
112 sig = inspect.signature(func_with_kwargs)
113 filter_keys = [param.name for param in sig.parameters.values()]
114 except:
115 # Python2 ...
116 filter_keys = inspect.getargspec(func_with_kwargs)[0]
117
118 filtered_dict = {
119 filter_key: dict_to_filter[filter_key]
120 for filter_key in filter_keys
121 if filter_key in dict_to_filter
122 }
123 return filtered_dict
124
125
126# ------------------------------------------------------- #

Callers 3

plot_epsFunction · 0.85
plot_fieldsFunction · 0.85
__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected