"vscode:/vscode.git/clone" did not exist on "1ed0aa8feab58a5cbdf2d79fdb718e3a5cc03525"
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:
# Default device is 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 json
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
from pytorch3d.common.datatypes import get_args, get_origin
_X = TypeVar("_X")
......
......@@ -12,10 +12,21 @@ import warnings
from collections import Counter, defaultdict
from enum import Enum
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 pytorch3d.common.datatypes import get_args, get_origin
"""
......
......@@ -7,7 +7,7 @@
import contextlib
import pathlib
import warnings
from typing import ContextManager, IO, Optional, Union
from typing import cast, ContextManager, IO, Optional, Union
import numpy as np
import torch
......@@ -17,14 +17,6 @@ from PIL import Image
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]
......@@ -36,7 +28,7 @@ def _open_file(f, path_manager: PathManager, mode: str = "r") -> ContextManager[
f = f.open(mode)
return contextlib.closing(f)
else:
return nullcontext(f)
return contextlib.nullcontext(cast(IO, f))
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