"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "1a099e5e0eaec0a78567bbf962a9419e6d411299"
Commit 3cf3998e authored by Jeremy Reizenstein's avatar Jeremy Reizenstein Committed by Facebook GitHub Bot
Browse files

assume Python 3.8+

Summary: Remove workarounds for Python 3.7

Reviewed By: davidsonic

Differential Revision: D42451534

fbshipit-source-id: 461dd311f3bccf7bef120ffe0b97fbbd173d95be
parent d71105f5
...@@ -57,19 +57,3 @@ def get_device(x, device: Optional[Device] = None) -> torch.device: ...@@ -57,19 +57,3 @@ def get_device(x, device: Optional[Device] = None) -> torch.device:
# Default device is cpu # Default device is cpu
return torch.device("cpu") return torch.device("cpu")
# Provide get_origin and get_args even in Python 3.7.
if sys.version_info >= (3, 8, 0):
from typing import get_args, get_origin
elif sys.version_info >= (3, 7, 0):
def get_origin(cls): # pragma: no cover
return getattr(cls, "__origin__", None)
def get_args(cls): # pragma: no cover
return getattr(cls, "__args__", None)
else:
raise ImportError("This module requires Python 3.7+")
...@@ -9,10 +9,21 @@ import dataclasses ...@@ -9,10 +9,21 @@ import dataclasses
import gzip import gzip
import json import json
from dataclasses import dataclass, Field, MISSING from dataclasses import dataclass, Field, MISSING
from typing import Any, cast, Dict, IO, Optional, Tuple, Type, TypeVar, Union from typing import (
Any,
cast,
Dict,
get_args,
get_origin,
IO,
Optional,
Tuple,
Type,
TypeVar,
Union,
)
import numpy as np import numpy as np
from pytorch3d.common.datatypes import get_args, get_origin
_X = TypeVar("_X") _X = TypeVar("_X")
......
...@@ -12,10 +12,21 @@ import warnings ...@@ -12,10 +12,21 @@ import warnings
from collections import Counter, defaultdict from collections import Counter, defaultdict
from enum import Enum from enum import Enum
from functools import partial from functools import partial
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union from typing import (
Any,
Callable,
Dict,
get_args,
get_origin,
List,
Optional,
Tuple,
Type,
TypeVar,
Union,
)
from omegaconf import DictConfig, OmegaConf, open_dict from omegaconf import DictConfig, OmegaConf, open_dict
from pytorch3d.common.datatypes import get_args, get_origin
""" """
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import contextlib import contextlib
import pathlib import pathlib
import warnings import warnings
from typing import ContextManager, IO, Optional, Union from typing import cast, ContextManager, IO, Optional, Union
import numpy as np import numpy as np
import torch import torch
...@@ -17,14 +17,6 @@ from PIL import Image ...@@ -17,14 +17,6 @@ from PIL import Image
from ..common.datatypes import Device from ..common.datatypes import Device
@contextlib.contextmanager
def nullcontext(x):
"""
This is just like contextlib.nullcontext but also works in Python 3.6.
"""
yield x
PathOrStr = Union[pathlib.Path, str] PathOrStr = Union[pathlib.Path, str]
...@@ -36,7 +28,7 @@ def _open_file(f, path_manager: PathManager, mode: str = "r") -> ContextManager[ ...@@ -36,7 +28,7 @@ def _open_file(f, path_manager: PathManager, mode: str = "r") -> ContextManager[
f = f.open(mode) f = f.open(mode)
return contextlib.closing(f) return contextlib.closing(f)
else: else:
return nullcontext(f) return contextlib.nullcontext(cast(IO, f))
def _make_tensor( def _make_tensor(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment