Skip to content

Commit 93735d2

Browse files
authored
Fix parameter inspection for dynamic MicroSimulation class (#255)
* fix dyn class param inspection and forwarding * add changelog
1 parent c479734 commit 93735d2

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## latest
44

5+
- Fixed `MicroSimulation` initialization requiring positional parameters [#255](https://github.com/precice/micro-manager/pull/255)
56
- Fixed model adaptivity convergence at resolution boundaries to prevent infinite loops for out-of-range switching requests [#252](https://github.com/precice/micro-manager/pull/252)
67
- Add function `set_global_id` to the dummies and the example in the integration test [#247](https://github.com/precice/micro-manager/pull/247)
78

micro_manager/micro_simulation.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,19 @@ def __getattr__(self, name):
555555
# Only add initialize override if the wrapped class actually has it,
556556
# so that requires_initialize() returns True for those classes.
557557
if has_initialize:
558-
class_body += """
559-
def initialize(self, *args, **kwargs):
560-
return self._wrapped.initialize(*args, **kwargs)
558+
argspec = inspect.getfullargspec(cls.initialize)
559+
# build args
560+
init_args = f"{', '.join(argspec.args)}"
561+
params = f"{', '.join(argspec.args[1::])}"
562+
if argspec.varargs is not None:
563+
init_args += f", *args"
564+
params += f", *args"
565+
if argspec.varkw is not None:
566+
init_args += f", **kwargs"
567+
params += f", **kwargs"
568+
class_body += f"""
569+
def initialize({init_args}):
570+
return self._wrapped.initialize({params})
561571
"""
562572

563573
# Only add output override if the wrapped class actually has it,

0 commit comments

Comments
 (0)