Skip to content

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

Merged
tlambert03 merged 2 commits into
pyapp-kit:mainfrom
Sanjays2402:fix/magic-factory-method-descriptor
Aug 29, 2026
Merged

fix: make MagicFactory work as a method descriptor#737
tlambert03 merged 2 commits into
pyapp-kit:mainfrom
Sanjays2402:fix/magic-factory-method-descriptor

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

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 90.15%. Comparing base (505321b) to head (0346afa).

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   90.15%   90.15%   -0.01%     
==========================================
  Files          43       43              
  Lines        5314     5323       +9     
==========================================
+ Hits         4791     4799       +8     
- Misses        523      524       +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.

@tlambert03

Copy link
Copy Markdown
Member

thanks for the fix! Sorry for the dealy

@tlambert03
tlambert03 merged commit 60da969 into pyapp-kit:main Aug 29, 2026
31 checks passed
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

2 participants