mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 20:02:49 +08:00
Avoid contextlib.nullcontext for Python 3.6 compatibility
Summary: As mentioned in a comment on https://github.com/facebookresearch/pytorch3d/issues/77, we can't use this function in Python 3.6. It's easy to write our own version. Reviewed By: gkioxari Differential Revision: D24249915 fbshipit-source-id: 4c70a3efb03daa115041d082e616511297eab8fa
This commit is contained in:
parent
f5383a7e5a
commit
8a9d20151d
@ -11,6 +11,14 @@ from fvcore.common.file_io import PathManager
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def nullcontext(x):
|
||||||
|
"""
|
||||||
|
This is just like contextlib.nullcontext but also works in Python 3.6.
|
||||||
|
"""
|
||||||
|
yield x
|
||||||
|
|
||||||
|
|
||||||
def _open_file(f, mode="r") -> ContextManager[IO]:
|
def _open_file(f, mode="r") -> ContextManager[IO]:
|
||||||
if isinstance(f, str):
|
if isinstance(f, str):
|
||||||
f = open(f, mode)
|
f = open(f, mode)
|
||||||
@ -19,7 +27,7 @@ def _open_file(f, mode="r") -> ContextManager[IO]:
|
|||||||
f = f.open(mode)
|
f = f.open(mode)
|
||||||
return contextlib.closing(f)
|
return contextlib.closing(f)
|
||||||
else:
|
else:
|
||||||
return contextlib.nullcontext(f)
|
return nullcontext(f)
|
||||||
|
|
||||||
|
|
||||||
def _make_tensor(
|
def _make_tensor(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user