Skip to content

Commit 20082a1

Browse files
sarahtranfbfacebook-github-bot
authored andcommitted
Fix mypy error in transformer_typing.py (#1543)
Summary: Pull Request resolved: #1543 Example failure: https://github.com/pytorch/captum/actions/runs/14346024555/job/40216163528 ``` captum/_utils/transformers_typing.py:52: error: Incompatible types in assignment (expression has type "type[DynamicCache]", variable has type "type[DynamicCacheLike] | None") [assignment] ``` Reviewed By: styusuf Differential Revision: D72685659 fbshipit-source-id: 348d6366fc47899e3dfde08dc71a7884abb86cc8
1 parent fb29751 commit 20082a1

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

captum/_utils/transformers_typing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# pyre-strict
44

5-
from typing import Any, Dict, Optional, Protocol, Tuple, Type
5+
from typing import Any, cast, Dict, Optional, Protocol, Tuple, Type
66

77
import torch
88

@@ -46,10 +46,7 @@ def from_legacy_cache(
4646
)
4747

4848
Cache = _Cache
49-
# pyre-ignore[9]: Incompatible variable type: DynamicCache is declared to have
50-
# type `Optional[Type[DynamicCacheLike]]` but is used as type
51-
# `Type[_DynamicCache]`
52-
DynamicCache = _DynamicCache
49+
DynamicCache = cast(Optional[Type[DynamicCacheLike]], _DynamicCache)
5350
except ImportError:
5451
Cache = DynamicCache = None
5552
else:

0 commit comments

Comments
 (0)