Skip to content

[bug] Incorrect type hint for name parameter in binary_var_list #101

@yishaishimoni

Description

@yishaishimoni

Description

The binary_var_list method in the docplex.mp.model API has an incorrect type annotation for the name parameter.

Current signature:

def binary_var_list(self, keys, lb=None, ub=None, name: type[str] = str, key_format=None):

The annotation type[str] suggests that the function expects the str class (a type), but according to the documentation and actual behavior, name should accept either:

  • a string (e.g., "x")
  • a function that generates names.

The default value str is used as a callable to convert keys to strings, which is valid, but the type hint does not reflect this.

Impact

Static type checkers incorrectly flag valid code like:

from docplex.mp.model import Model

model = Model(name="my example problem")
x = model.binary_var_list([1, 3], name="x")

Users must resort to # type: ignore or cast hacks.

Suggested fix

Change the function signature to

def binary_var_list(self, keys, lb=None, ub=None, name: str | Callable[..., str] = str, key_format=None):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions