Skip to content

Add methodize: bind method params to instance attributes of any name - #115

Merged
thorwhalen merged 2 commits into
masterfrom
feat/20-methodize
Oct 20, 2026
Merged

thorwhalen merged 2 commits into
masterfrom
feat/20-methodize

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Closes #20.

func_to_method_func (i2.wrapper) already made methods sourcing params from instance attributes, but only from attributes of the same name (other names needed a ch_names wrap first). This adds what #20 asked for:

  • bind_spec_to_dict(bind): normalizes 'x y', ['x', ('z', 'zoo')] or {'z': 'zoo'} to {param: attr}.
  • func_to_method_func(func, instance_params) and kwargs_trans_to_extract_args_from_attrs(..., attr_names) accept any such spec (names still work as before).
  • methodize(func, bind=..., *, method_name=None, instance_arg_name='self'): the facade with the issue's name and argument, exported from i2. The issue's example is its doctest.
  • Removes the commented-out methodize / _instance_extractor draft it replaces.

Not done: the issue's footnote (1), keeping a bound param in the signature with only its default sourced from the instance. Filed as #112.

Tests: i2 suite 850 passed; ruff check i2 clean.

🤖 Generated with Claude Code

thorwhalen and others added 2 commits October 20, 2026 14:07
func_to_method_func's instance_params (and kwargs_trans_to_extract_args_from_attrs)
now accept (param, attr) pairs or a {param: attr} mapping besides names, via the
new bind_spec_to_dict. methodize(func, bind=...) is the facade #20 asked for.
The commented-out draft it replaces is removed.

Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bind_spec_to_dict rejects malformed items and params bound twice with clear
errors; bind_funcs_object_attrs raises a clear TypeError for renaming specs
(it binds same-name attributes only) instead of building a wrong class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 661b43e into master Oct 20, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the feat/20-methodize branch October 20, 2026 14:50
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.

Transform a function to a method sourcing some arguments from instance (i2.wrapper use case)

1 participant