Skip to content

Commit

Permalink
use TYPE_CHECKING instead of False
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Rauber committed Jan 31, 2020
1 parent 91a9253 commit 8c5d550
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion eagerpy/modules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from importlib import import_module
import inspect
from types import ModuleType
from typing import Any
import functools

from .astensor import astensor
Expand Down Expand Up @@ -32,7 +33,7 @@ def __dir__(self):
# makes sure tab completion works
return import_module(self.__name__).__dir__()

def __getattr__(self, name):
def __getattr__(self, name: str) -> Any:
attr = getattr(import_module(self.__name__), name)
if callable(attr):
attr = wrap(attr)
Expand Down
5 changes: 3 additions & 2 deletions eagerpy/tensor/jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

# from .tensor import Tensor

from typing import Tuple, cast, Union, Any, TypeVar
from typing import Tuple, cast, Union, Any, TypeVar, TYPE_CHECKING
from importlib import import_module
from collections.abc import Iterable
import numpy as onp


if False:
if TYPE_CHECKING:
# for static analyzers
import jax
import jax.numpy as np
else:
# lazy import in JAXTensor
jax = None
np = None

Expand Down
7 changes: 4 additions & 3 deletions eagerpy/tensor/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import numpy as np
from collections.abc import Iterable
from typing import Tuple, cast, Union, Any, TypeVar
from typing import Tuple, cast, Union, Any, TypeVar, TYPE_CHECKING
from importlib import import_module


if False:
if TYPE_CHECKING:
import torch # for static analyzers
else:
torch = None # type: ignore
# lazy import in PyTorchTensor
torch = None


Tensor = TypeVar("Tensor", bound="PyTorchTensor")
Expand Down
5 changes: 3 additions & 2 deletions eagerpy/tensor/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .. import index

import functools
from typing import Tuple, cast, Union, Any, TypeVar, Callable
from typing import Tuple, cast, Union, Any, TypeVar, Callable, TYPE_CHECKING
from importlib import import_module
from collections.abc import Iterable
import numpy as np
Expand All @@ -17,9 +17,10 @@
F = TypeVar("F", bound=FuncType)


if False:
if TYPE_CHECKING:
import tensorflow as tf # for static analyzers
else:
# lazy import in TensorFlowTensor
tf = None


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain if tests don't hit defensive assertion code:
@abstractmethod
@overload
TYPE_CHECKING

0 comments on commit 8c5d550

Please sign in to comment.