Replies: 4 comments 3 replies
-
Yes the idea of |
Beta Was this translation helpful? Give feedback.
-
One more question. When is the |
Beta Was this translation helpful? Give feedback.
-
@alfonsogarciacaro Not really sure how to proceed here. Translating Using the new DecoratorAttribute is also possible, but the generated becomes nested. Both JS (experimental) and Python have decorators so it would be nice if we could generate proper decorators. E.g for code such as: type MeasurePerformanceAttribute () =
inherit Py.DecoratorAttribute()
override _.Decorate(fn: Py.Callable) =
Py.argsFunc(fun args ->
let sw = System.Diagnostics.Stopwatch()
sw.Start()
let res = fn.Invoke(args)
sw.Stop()
res
)
[<MeasurePerformance>]
let myExpensiveCalculation x y = x + y This generates the following Python: class MeasurePerformanceAttribute:
def __init__(self, __unit: Literal[None]=None) -> None:
pass
def Decorate(self, fn: Callable[..., Any]) -> Callable[..., Any]:
def _arrow3(args: Array[Any]) -> Any:
sw: Any = StopWatch()
sw.start()
res: Any = fn(*args)
sw.stop()
return res
return lambda *args: _arrow3(args)
MeasurePerformanceAttribute_reflection = _expr4
def MeasurePerformanceAttribute__ctor(__unit: Literal[None]=None) -> MeasurePerformanceAttribute:
return MeasurePerformanceAttribute(__unit)
def _arrow5(x: int, y: int) -> int:
return x + y
my_expensive_calculation: Callable[[int, int], int] = MeasurePerformanceAttribute().Decorate(_arrow5) However what I would like to generate is something like below. An idea would be to add decorators as a property of class MeasurePerformanceAttribute:
def __init__(self, __unit: Literal[None]=None) -> None:
pass
def __call__(self, fn: Callable[..., Any]) -> Callable[..., Any]:
def _arrow3(args: Array[Any]) -> Any:
sw: Any = StopWatch()
sw.start()
res: Any = fn(*args)
sw.stop()
return res
return lambda *args: _arrow3(args)
MeasurePerformanceAttribute_reflection = _expr4
def MeasurePerformanceAttribute__ctor(__unit: Literal[None]=None) -> MeasurePerformanceAttribute:
return MeasurePerformanceAttribute(__unit)
@MeasurePerformanceAttribute()
def my_expensive_calculation(x: int, y: int) -> int:
return x + y Any ideas? |
Beta Was this translation helpful? Give feedback.
-
What I want is to get better XUnit handling for Fable.Python. The idea is to use Fable plugins for translating the XUnit attributes to pytest decorators:
The
Fact
attribute should make sure the test function starts withtest
or else it will prependtest
.The
Theory
andÌnlineData
attributes should translate toparameterize
lists.I'm trying to do this using Fable plugins. The
Transform
member has signatureMemberDecl -> MemberDecl
so I can see the functions and get the attributes, but since I cannot prepend anything (e.gFable.Emit
), I need to return e.g a nested function that I need to know inFable2Python.fs
that these nested functions should then be rewritten as decorators. So I need to give some kind of hint. Would it be ok to useMemberDecl.Tags
for this. E.g. use a tag"decorator"
or is the.Tags
ment for something else? Or is there a better way to do this?Beta Was this translation helpful? Give feedback.
All reactions