mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
assume Python 3.8+
Summary: Remove workarounds for Python 3.7 Reviewed By: davidsonic Differential Revision: D42451534 fbshipit-source-id: 461dd311f3bccf7bef120ffe0b97fbbd173d95be
This commit is contained in:
parent
d71105f5e5
commit
3cf3998ea5
@ -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
|
|||||||
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
|
|||||||
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 @@
|
|||||||
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
|
|||||||
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[
|
|||||||
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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user