Skip to content

fix: make MagicFactory work as a method descriptor - #737

Open
Sanjays2402 wants to merge 1 commit into
pyapp-kit:mainfrom
Sanjays2402:fix/magic-factory-method-descriptor
Open

fix: make MagicFactory work as a method descriptor#737
Sanjays2402 wants to merge 1 commit into
pyapp-kit:mainfrom
Sanjays2402:fix/magic-factory-method-descriptor

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #733

functools.partial had no __get__ before Python 3.13, so a @magic_factory used on a method never received the instance; from 3.13 on partial.__get__ binds the instance as the first positional argument, which MagicFactory.__call__ rejects. Either way calling the resulting widget raised TypeError: missing a required argument: 'self'.

MagicFactory now implements __get__ itself and returns a factory that binds its first parameter to the instance, mirroring FunctionGui.__get__. New tests/test_factory.py::test_magic_factory_as_method fails without the fix and passes with it.

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

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.32%. Comparing base (2f08fb3) to head (83c6ab5).

Files with missing lines Patch % Lines
src/magicgui/type_map/_magicgui.py 88.88% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@magic_factory doesn't work as a method descriptor properly

1 participant