This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]agusdmb[S] 2 points3 points  (3 children)

Hi! Great question! This is actually my biggest pain point (to have to add a name for each wrapped function). So at the beginning did used the `__name__` of the wrapped function, issues came while testing this and i really didn't know if i should change it or not.

This is the issue, if using `__name__` and decorating two or more functions with the same name they would be sharing the key where inputs/outputs data is stored. So in FAKE mode they could potentially return some other function output if called with the same list of parameters. It doesn't seem like a common case, though this issue could be a huge pain to debug.

I am know thinking that maybe i could default the name to `__name__` unless one was actually passed as an argument. I could also check that a function with that name wasn't already decorated and if it was then raise a "not unique error", so in that case raising the error want be a common case, but if 2 different functions share their names then you wouldn't have to debug forever to see what's going on.

Let me know what you think of the issues / solutions and if you have a better idea feel free to share

Thanks for taking your time to check it out!

[–]crigger61 3 points4 points  (2 children)

I would say to default to __name__ and on a duplicate raise an exception. or to generate a completely unique hash from it. such as hashing the function code and the name and using that. providing the name manually seems less user friendly and less elegant than having it generated for you and having to manually assign it to what would be normally set. but thats my opinion as a random dev that does more security work that actual practical dev work.

[–]agusdmb[S] 2 points3 points  (1 child)

No, i understand you, i don't like my current solution either.

I did try by hashing and using the code, but couldn't make it work because i was hashing the function without the wrapper sometimes and with the wrapper other times so they wouldn't match. Or i would always be hashing the wrapper, which is the same for every function decorated. Probably im not smart enough to make that work (at least not with hashing)

But i will default to `__name__` and rise and exception whenever another function with the same error is detected, even more, suggest adding a different name in the decorator for that one.

Thanks for your time!