Skip to content

Method *args, **kwargs produces wrong parameter order #62

@swernerx

Description

@swernerx

Bug Description

In class methods, *args, **kwargs produces ...args, kwargs which is invalid TypeScript (rest parameter must be last).

Python Input

class MyClass:
    def _init_stage_2(self, pyfunc, *args, **kwargs):
        self.pyfunc = pyfunc

Current Output

class MyClass {
  _init_stage_2(pyfunc, ...args, kwargs) {  // ERROR: rest must be last
    this.pyfunc = pyfunc
  }
}

Expected Output

class MyClass {
  _init_stage_2(pyfunc, kwargs: Record<string, unknown> = {}, ...args) {
    this.pyfunc = pyfunc
  }
}

Note

This works correctly for standalone functions, but not for class methods.

Context

Found in numpy/lib/_function_base_impl.py during NumPy migration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions