Skip to content

Commit

Permalink
Fixed mypy failures on the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vfdev-5 committed Oct 17, 2024
1 parent 8782ca4 commit 6872133
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ignite/handlers/time_profilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def print_results(results: Dict) -> str:
"""

def to_str(v: Union[str, tuple]) -> str:
def to_str(v: Union[str, tuple, int, float]) -> str:
if isinstance(v, str):
return v
elif isinstance(v, tuple):
Expand All @@ -412,12 +412,12 @@ def odict_to_str(d: Mapping) -> str:
return out

others = {
k: odict_to_str(v) if isinstance(v, OrderedDict) else v for k, v in results["event_handlers_stats"].items()
k: odict_to_str(v) if isinstance(v, OrderedDict) else to_str(v) for k, v in results["event_handlers_stats"].items()
}

others.update(results["event_handlers_names"])

output_message = """
output_message: str = """
----------------------------------------------------
| Time profiling stats (in seconds): |
----------------------------------------------------
Expand All @@ -430,7 +430,7 @@ def odict_to_str(d: Mapping) -> str:
{dataflow_stats}
Event handlers:
{total_time:.5f}
{total_time}
- Events.STARTED: {STARTED_names}
{STARTED}
Expand Down
8 changes: 4 additions & 4 deletions ignite/handlers/visdom_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(
**kwargs: Any,
):
try:
import visdom
import visdom # type: ignore[import-not-found]
except ImportError:
raise ModuleNotFoundError(
"This contrib module requires visdom package. "
Expand Down Expand Up @@ -187,15 +187,15 @@ def __init__(

self.vis = visdom.Visdom(server=server, port=port, raise_exceptions=raise_exceptions, **kwargs)

if not self.vis.offline and not self.vis.check_connection(): # type: ignore[attr-defined]
if not self.vis.offline and not self.vis.check_connection():
raise RuntimeError(f"Failed to connect to Visdom server at {server}. Did you run python -m visdom.server ?")

self.executor: Union[_DummyExecutor, "ThreadPoolExecutor"] = _DummyExecutor()
if num_workers > 0:
self.executor = ThreadPoolExecutor(max_workers=num_workers)

def _save(self) -> None:
self.vis.save([self.vis.env]) # type: ignore[attr-defined]
self.vis.save([self.vis.env])

def close(self) -> None:
self.executor.shutdown()
Expand Down Expand Up @@ -240,7 +240,7 @@ def add_scalar(
kwargs = {
"X": [global_step],
"Y": [v],
"env": logger.vis.env, # type: ignore[attr-defined]
"env": logger.vis.env,
"win": self.windows[k]["win"],
"update": update,
"opts": self.windows[k]["opts"],
Expand Down
2 changes: 1 addition & 1 deletion ignite/handlers/wandb_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def score_function(engine):

def __init__(self, *args: Any, **kwargs: Any):
try:
import wandb
import wandb # type: ignore[import-not-found]

self._wandb = wandb
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions ignite/metrics/fbeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def thresholded_output_transform(output):

if precision is None:
precision = Precision(
output_transform=(lambda x: x) if output_transform is None else output_transform, # type: ignore[arg-type]
output_transform=(lambda x: x) if output_transform is None else output_transform,
average=False,
device=device,
)
Expand All @@ -160,7 +160,7 @@ def thresholded_output_transform(output):

if recall is None:
recall = Recall(
output_transform=(lambda x: x) if output_transform is None else output_transform, # type: ignore[arg-type]
output_transform=(lambda x: x) if output_transform is None else output_transform,
average=False,
device=device,
)
Expand Down

0 comments on commit 6872133

Please sign in to comment.