Skip to content

Commit ada145b

Browse files
committed
Literal use w/ python < 3.8 requires typing_extension, cach instead of check sys ver
1 parent dfaab97 commit ada145b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

timm/models/_hub.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import logging
44
import os
5-
import sys
65
from functools import partial
76
from pathlib import Path
87
from tempfile import TemporaryDirectory
@@ -22,9 +21,9 @@
2221
except ImportError:
2322
_has_safetensors = False
2423

25-
if sys.version_info >= (3, 8):
24+
try:
2625
from typing import Literal
27-
else:
26+
except ImportError:
2827
from typing_extensions import Literal
2928

3029
from timm import __version__

timm/models/vision_transformer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
import math
2828
from collections import OrderedDict
2929
from functools import partial
30-
from typing import Any, Callable, Dict, Optional, Sequence, Set, Tuple, Type, Union, Literal, List
30+
from typing import Any, Callable, Dict, Optional, Sequence, Set, Tuple, Type, Union, List
31+
try:
32+
from typing import Literal
33+
except ImportError:
34+
from typing_extensions import Literal
3135

3236
import torch
3337
import torch.nn as nn

0 commit comments

Comments
 (0)