fix: make MagicFactory work as a method descriptor - #737
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
magic_factory used on a method did not bind the instance: functools.partial had no __get__ before Python 3.13, so self was never passed, and from 3.13 on partial.__get__ binds the instance as the first positional argument of the factory (which only accepts keyword arguments). Either way calling the resulting widget raised TypeError: missing a required argument: 'self'. MagicFactory now implements __get__ itself, returning a factory whose first parameter is bound to the instance, mirroring FunctionGui.__get__. Adds tests/test_factory.py::test_magic_factory_as_method.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
==========================================
- Coverage 89.32% 89.32% -0.01%
==========================================
Files 40 40
Lines 4835 4844 +9
==========================================
+ Hits 4319 4327 +8
- Misses 516 517 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #733
functools.partialhad no__get__before Python 3.13, so a@magic_factoryused on a method never received the instance; from 3.13 onpartial.__get__binds the instance as the first positional argument, whichMagicFactory.__call__rejects. Either way calling the resulting widget raisedTypeError: missing a required argument: 'self'.MagicFactorynow implements__get__itself and returns a factory that binds its first parameter to the instance, mirroringFunctionGui.__get__. Newtests/test_factory.py::test_magic_factory_as_methodfails without the fix and passes with it.