Repository navigation
Add methodize: bind method params to instance attributes of any name - #115
Merged
Merged
Conversation
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>
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 #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 ach_nameswrap 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)andkwargs_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 fromi2. The issue's example is its doctest.methodize/_instance_extractordraft 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 i2clean.🤖 Generated with Claude Code