-
Notifications
You must be signed in to change notification settings - Fork 327
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
[Feature] Added implement_for
decorator
#618
Conversation
@vmoens I have a question about the following case: when installed version of the module doesn't fit any implementation. Which one is preferable from your perspective? |
One option could be that if we use @implemented_for("gym", None, "0.13")
def fun():
foo()
@implemented_for("gym", "0.13", None)
def fun():
foo() is valid but @implemented_for("gym", None, "0.13")
def fun():
foo()
@implemented_for("gym", "0.13", "0.14")
def fun():
foo() will return an exception during import. There are caveats with this (it's an optimistic view on future releases), but at least if nothing is expected to break with a new release our CI will just pass. If something breaks, it means we need one more function implementation. What do you think? |
With what I suggested as more strict option there won't be an import time exception. The decorated function will become something like:
So exception will be thrown only if Such strict behaviour is not typical for python and forcing user to implement "extra" functions might not be a good idea, that is why I decided to implement it like I did. Unless, you think that catching the situation when function is called with unsupported (potentially) version of a module beforehand is more often beneficial than inconvenient. Also, I just realised that I haven't considered "from_version" as None for some reason, but it does look reasonable to allow it, I will do it. |
Codecov Report
@@ Coverage Diff @@
## main #618 +/- ##
==========================================
- Coverage 87.92% 87.82% -0.10%
==========================================
Files 125 125
Lines 24218 24280 +62
==========================================
+ Hits 21293 21324 +31
- Misses 2925 2956 +31
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
My suggestion was a bit in the spirit of |
Alright, I will change the behaviour, so the decorator will replace the function with a mock that raises the exception by default (until fitting implementation found). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor fixes and we're good to go!
Thanks for this!
Description
Added the decorator that allows to specify with which version of a given module a function is compatible with. Fitting implementation is selected basing on installed version of the module.
Motivation and Context
It is required for bc-braking packages (e.g. "gym"), so we can have several implementations of the same function for different versions of a module. Proposed by @vmoens.
Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!