Skip to content

OutputHandler typing issue: metric_names should accept str as well as Optional[List[str]] in all logger handlers #3479

@gabrielfruet

Description

@gabrielfruet

🐛 Bug description

The typing for the metric_names parameter in OutputHandler-derived classes is too restrictive in several files. The signature currently expects Optional[List[str]], but according to usage in documentation and code, it should also allow a str value (e.g., "all").

  • The base class in ignite/handlers/base_logger. py BaseOutputHandler is correct:

    metric_names: Optional[Union[str, List[str]]] = None
  • But all the logger OutputHandler implementations in these files override it with the more restrictive type:

    • ignite/handlers/tensorboard_logger.py
    • ignite/handlers/wandb_logger.py
    • ignite/handlers/mlflow_logger.py
    • ignite/handlers/polyaxon_logger. py
    • ignite/handlers/visdom_logger.py
    • ignite/handlers/neptune_logger.py
    • ignite/handlers/clearml_logger.py

    All of these should also use Optional[Union[str, List[str]]] for metric_names for full typing correctness and consistency with the base class and library usage.

Current signature:

metric_names: Optional[List[str]] = None

Expected signature (type hint):

metric_names:  Union[str, Optional[List[str]]] = None
# or, preferably, to match the base:
metric_names:  Optional[Union[str, List[str]]] = None

This would align the typing with examples and usage where a string like "all" is passed.

Location: All logger OutputHandler classes (see list above), parameter metric_names

Steps to reproduce:

  • Try type checking with metric_names="all" for OutputHandler in any logger module; type checker (e.g. mypy) issues an error.
  • Documentation also shows examples where a string is allowed.

Expected behavior:

  • Typing should reflect that both string (e.g., "all") and List[str] are allowed for metric_names in all OutputHandler classes.

Pull request
If this change is approved, i would like to create a PR.

Environment

  • PyTorch Version:
  • Ignite Version:
  • OS:
  • How you installed Ignite (conda, pip, source):
  • Python version:
  • Any other relevant information:

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