-
-
Notifications
You must be signed in to change notification settings - Fork 692
OutputHandler typing issue: metric_names should accept str as well as Optional[List[str]] in all logger handlers #3479
Description
🐛 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. pyBaseOutputHandler 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.pyignite/handlers/wandb_logger.pyignite/handlers/mlflow_logger.pyignite/handlers/polyaxon_logger. pyignite/handlers/visdom_logger.pyignite/handlers/neptune_logger.pyignite/handlers/clearml_logger.py
All of these should also use
Optional[Union[str, List[str]]]formetric_namesfor full typing correctness and consistency with the base class and library usage.
Current signature:
metric_names: Optional[List[str]] = NoneExpected signature (type hint):
metric_names: Union[str, Optional[List[str]]] = None
# or, preferably, to match the base:
metric_names: Optional[Union[str, List[str]]] = NoneThis 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_namesin 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: