Skip to content

Modify define_function_handling_dict_from_class to inject function to module directly - #4752

Draft
alejoe91 wants to merge 1 commit into
mainfrom
modify-define-function
Draft

Modify define_function_handling_dict_from_class to inject function to module directly#4752
alejoe91 wants to merge 1 commit into
mainfrom
modify-define-function

Conversation

@alejoe91

@alejoe91 alejoe91 commented Sep 3, 2026

Copy link
Copy Markdown
Member

Having something like:

bandpass_filter = define_function_handling_dict_from_class(BandpassFilterRecording, name="bandpass_filter")

extends the function to work with individual recordings and dicts of. The function signature and name are set to match the class and provided name. This could cause mismatches in the naming.

This PR uses a trick to add the new wrapped function directly to the caller module.

Related to #4319 : I suggest we do the same for define_funtction_from_class (already 2 mismatches found!!!) and use the pyi approach that Graham suggested to make IDEs happy.

@chrishalcrow @grahamfindlay thoughts?

@alejoe91 alejoe91 added core Changes to core module refactor Refactor of code, with no change to functionality labels Sep 3, 2026
import zarr


def define_function_handling_dict_from_class(source_class, name):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename register_* instead

@alejoe91
alejoe91 marked this pull request as draft September 8, 2026 14:02
@grahamfindlay

Copy link
Copy Markdown
Contributor

Sorry it took me a while to get to this! I was on vacation :)

I looked up sys._get_frame to understand how this works, and noticed the following warning:

CPython implementation detail: This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.

It's probably safe to assume that the vast majority of users are running Python, but I don't know that for a fact, and it does make me leery.

I do see the rationale behind this trick, though.

I think there might be a better solution than .pyi approach that I outlined in #4319 that could solve both this issue (i.e. would give a single source of truth for both the exported function name and the function's __name__) and the static analysis issue. I will write it up in #4319.

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

Labels

core Changes to core module refactor Refactor of code, with no change to functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants