Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Defining custom class without docval prevents read #1159

Open
rly opened this issue Aug 1, 2024 · 0 comments
Open

[Bug]: Defining custom class without docval prevents read #1159

rly opened this issue Aug 1, 2024 · 0 comments
Assignees
Labels
category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Milestone

Comments

@rly
Copy link
Contributor

rly commented Aug 1, 2024

What happened?

Example here: catalystneuro/ndx-anatomical-localization#1

When the constructor of a registered class uses a list of arguments instead of docval as in:

@register_class("Space", "ndx-anatomical-localization")
class Space(TempSpace):
    def __init__(self, name, space_name, origin, units, orientation):

The construct process relies on docval to set the kwargs that are passed to the class constructor:

        # build kwargs for the constructor
        kwargs = dict()
        for const_arg in get_docval(cls.__init__):
            # ...
            kwargs[argname] = val
        try:
            obj = self.__new_container__(cls, builder.source, parent, builder.attributes.get(self.__spec.id_key()),
                                         **kwargs)

Here, kwargs is empty. This results in a ConstructError on the last line above that says all required arguments are missing.

I suggest we change the construct process to use https://docs.python.org/3.12/library/inspect.html#introspecting-callables-with-the-signature-object in addition to docval until docval is removed.

This is not blocking because extension builders can still define their __init__ with docval, but it would be nice to change as we transition away from using docval.

Steps to Reproduce

See example above

Traceback

No response

Operating System

macOS

Python Executable

Conda

Python Version

3.12

Package Versions

No response

@rly rly added category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s) labels Aug 1, 2024
@rly rly added this to the Next Major Release - 4.0 milestone Aug 1, 2024
@rly rly assigned rly and mavaylon1 Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
Development

No branches or pull requests

2 participants