Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Fixes does function wrapping #244 #245

Closed
wants to merge 2 commits into from
Closed

Fixes does function wrapping #244 #245

wants to merge 2 commits into from

Conversation

skrawcz
Copy link
Collaborator

@skrawcz skrawcz commented Dec 14, 2022

In issue #244 types were not being propagated of the function being wrapped.

This changes that by adding the functools.wraps decorator.

Adds a unit test to test for two decorators playing nice together and verified that it's broken before and fixed afterwards.

Changes

  • modifies @does wrapper function to properly emulate the signature of the function it is replacing.

How I tested this

  • locally
  • unit test

Notes

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

In issue #244 types were not being propagated of
the function being wrapped.

This changes that by adding the functools.wraps
decorator.

Adds a unit test to test for two decorators playing nice
together and verified that it's broken before and fixed
afterwards.
Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment about something that doesn't make sense but let's ship for the users.

@@ -754,7 +755,7 @@ def replacing_function(__fn=fn, **kwargs):
final_kwarg_values = does.map_kwargs(final_kwarg_values, self.argument_mapping)
return self.replacing_function(**final_kwarg_values)

return node.Node.from_fn(fn).copy_with(callabl=replacing_function)
return node.Node.from_fn(fn).copy_with(callabl=wrapper_function)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so let's ship this as it fixes it. I'm confused as to how this didn't take the original function:

typ=self.type,
. It should have used the initial type... Need to dig in.

Copy link
Collaborator Author

@skrawcz skrawcz Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, that's not the fix.

  1. I found it confusing that the callable created was named the same as the internal function -- hence this change.
  2. The actual fix is the functools.wraps and removing __fn parameter.

tests/test_graph.py Outdated Show resolved Hide resolved
@skrawcz
Copy link
Collaborator Author

skrawcz commented Dec 18, 2022

Closing in favor of #247 .

@skrawcz skrawcz closed this Dec 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants