Skip to content

CI typing issue with ignite/handlers/param_scheduler.py and ignite/handlers/lr_finder.py #3499

@vfdev-5

Description

@vfdev-5

There is the following typing error revealed by pyrefly:

INFO Checking project configured at `/home/runner/work/ignite/ignite/pyrefly.toml`
ERROR `list[float]` is not assignable to attribute `base_lrs` with type `list[Tensor | float]` [bad-assignment]
   --> ignite/handlers/lr_finder.py:543:25
    |
543 |         self.base_lrs = start_lrs
    |                         ^^^^^^^^^
    |
ERROR Class member `_ExponentialLR.get_lr` overrides parent class `_LRScheduler` in an inconsistent manner [bad-override]
   --> ignite/handlers/lr_finder.py:545:9
    |
545 |     def get_lr(self) -> List[float]:
    |         ^^^^^^
    |
  `_ExponentialLR.get_lr` has type `BoundMethod[_ExponentialLR, (self: _ExponentialLR) -> list[float]]`, which is not assignable to `BoundMethod[_ExponentialLR, (self: _ExponentialLR) -> list[Tensor | float]]`, the type of `_LRScheduler.get_lr`
ERROR Returned type `list[Tensor | Unknown]` is not assignable to declared return type `list[float]` [bad-return]
   --> ignite/handlers/lr_finder.py:548:16
    |
548 |         return [base_lr * (end_lr / base_lr) ** r for end_lr, base_lr in zip(self.end_lrs, self.base_lrs)]
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
ERROR Returned type `list[Tensor | float]` is not assignable to declared return type `list[float]` [bad-return]
   --> ignite/handlers/param_scheduler.py:900:16
    |
900 |           return [
    |  ________________^
901 | |             eta_min
902 | |             + (base_lr - eta_min) * (1 + math.cos(math.pi * self._lr_scheduler.T_cur / self._lr_scheduler.T_i)) / 2
903 | |             for base_lr in self._lr_scheduler.base_lrs
904 | |         ]
    | |_________^
    |
ERROR Returned type `Tensor | float` is not assignable to declared return type `float | list[float]` [bad-return]
   --> ignite/handlers/param_scheduler.py:998:20
    |
998 |             return lr_list[0]
    |                    ^^^^^^^^^^
    |
ERROR Returned type `list[Tensor | float] | list[float]` is not assignable to declared return type `float | list[float]` [bad-return]
    --> ignite/handlers/param_scheduler.py:1000:20
     |
1000 |             return lr_list
     |                    ^^^^^^^
     |
Error: `list[float]` is not assignable to attribute `base_lrs` with type `list[Tensor | float]`
Error: Class member `_ExponentialLR.get_lr` overrides parent class `_LRScheduler` in an inconsistent manner
  `_ExponentialLR.get_lr` has type `BoundMethod[_ExponentialLR, (self: _ExponentialLR) -> list[float]]`, which is not assignable to `BoundMethod[_ExponentialLR, (self: _ExponentialLR) -> list[Tensor | float]]`, the type of `_LRScheduler.get_lr`
Error: Returned type `list[Tensor | Unknown]` is not assignable to declared return type `list[float]`
Error: Returned type `list[Tensor | float]` is not assignable to declared return type `list[float]`
Error: Returned type `Tensor | float` is not assignable to declared return type `float | list[float]`
Error: Returned type `list[Tensor | float] | list[float]` is not assignable to declared return type `float | list[float]`
 INFO 6 errors (102 suppressed)
Error: Process completed with exit code 1.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions