Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for monitor with product type arguments #299

Merged
merged 6 commits into from
Feb 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix style
  • Loading branch information
leonardt committed Feb 12, 2021
commit a4208bcbe207b923a26f863257f862c4acd00414
21 changes: 13 additions & 8 deletions fault/pysv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ def leave_FunctionDef(self, original_node, updated_node):
if param.annotation is None:
new_params.append(param)
else:
T = eval(to_module(param.annotation.annotation).code, dict(self.env))
T = eval(to_module(param.annotation.annotation).code,
dict(self.env))
if not issubclass(T, m.Product):
raise NotImplementedError()
flat_args, nested_args = _gen_product_args(param.name.value, T)
new_params.extend(cst.Param(cst.Name(arg)) for arg in flat_args)
prelude.append(cst.parse_statement(f"{param.name.value} = {nested_args}"))
flat_args, nested_args = _gen_product_args(
param.name.value, T)
new_params.extend(
cst.Param(cst.Name(arg)) for arg in flat_args)
prelude.append(
cst.parse_statement(
f"{param.name.value} = {nested_args}"))
return updated_node.with_changes(
params=updated_node.params.with_changes(params=new_params),
body=updated_node.body.with_changes(
Expand Down Expand Up @@ -86,10 +91,10 @@ def __init__(self, pre_passes=[], post_passes=[],
file_name=file_name)

def exec(self,
etree: tp.Union[cst.ClassDef, cst.FunctionDef],
stree: tp.Union[cst.ClassDef, cst.FunctionDef],
env: SymbolTable,
metadata: tp.MutableMapping):
etree: tp.Union[cst.ClassDef, cst.FunctionDef],
stree: tp.Union[cst.ClassDef, cst.FunctionDef],
env: SymbolTable,
metadata: tp.MutableMapping):
result = super().exec(etree, stree, env, metadata)
result.observe._orig_args_ = metadata["_orig_observe_args_"]
result._source_code_ = to_module(stree).code
Expand Down