-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Currently Scan is only validating correctly if initialised through the scan decorator:
FastCS/src/fastcs/cs_methods.py
Lines 60 to 61 in bdab4fa
| if not len(self.parameters) == 1: | |
| raise FastCSException("Scan method cannot have arguments") |
This is because inspect.Signature.parameters will ignore self, but not in the wrapped case:
import inspect
class SomeClass:
def __init__(self, fn, b):
print(f"someclass fn {fn.__name__}", inspect.signature(fn).parameters)
def dec(b: str):
def wrapper(fn):
fn.wrapped_foo = SomeClass(fn, b)
return wrapper
class X:
def __init__(self):
print("internal foo", inspect.signature(self.foo).parameters)
print("internal bar", inspect.signature(self.bar).parameters)
SomeClass(self.foo, "c")
async def foo(self): ...
async def bar(self, a: str): ...
@dec("b")
async def wrapped_foo(self): ...
x = X()gives us
someclass fn wrapped_foo OrderedDict([('self', <Parameter "self">)])
internal foo OrderedDict()
internal bar OrderedDict([('a', <Parameter "a: str">)])
someclass fn foo OrderedDict()
I would like to be able to pass a poll period into my controller at init time
class PandaController(Controller):
def __init__(self, hostname: str, poll_period: float) -> None:
...
self.fastcs_method = Scan(self.update, poll_period)but this leads to no parameters and the check above failing because the expected self argument isn't present.
Suggestion
Change
FastCS/src/fastcs/cs_methods.py
Lines 60 to 61 in bdab4fa
| if not len(self.parameters) == 1: | |
| raise FastCSException("Scan method cannot have arguments") |
to
if self.parameters and tuple(self.parameters.keys()) != ("self",):
raise FastCSException("Scan method cannot have arguments")Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done