提交 b889ec1e authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Fix use of typing.NoReturn

上级 62651c4a
"""A container for specifying and manipulating a graph with distinct inputs and outputs."""
import time
from collections import OrderedDict
from typing import Any, Dict, List, NoReturn, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union
import aesara
from aesara.configdefaults import config
......@@ -171,7 +171,7 @@ class FunctionGraph(MetaObject):
self.profile = None
self.update_mapping = update_mapping
def add_input(self, var: Variable, check: bool = True) -> NoReturn:
def add_input(self, var: Variable, check: bool = True) -> None:
"""Add a new variable as an input to this `FunctionGraph`.
Parameters
......@@ -186,7 +186,7 @@ class FunctionGraph(MetaObject):
self.setup_var(var)
self.variables.add(var)
def setup_var(self, var: Variable) -> NoReturn:
def setup_var(self, var: Variable) -> None:
"""Set up a variable so it belongs to this `FunctionGraph`.
Parameters
......@@ -196,7 +196,7 @@ class FunctionGraph(MetaObject):
"""
self.clients.setdefault(var, [])
def setup_node(self, node: Apply) -> NoReturn:
def setup_node(self, node: Apply) -> None:
"""Set up node so it belongs to this `FunctionGraph`.
Parameters
......@@ -220,7 +220,7 @@ class FunctionGraph(MetaObject):
" the values must be tuples or lists."
)
def disown(self) -> NoReturn:
def disown(self) -> None:
"""Clear internal variables."""
for f in self._features:
self.remove_feature(f)
......@@ -236,7 +236,7 @@ class FunctionGraph(MetaObject):
"""Return a list of all the `(node, i)` pairs such that `node.inputs[i]` is `var`."""
return self.clients[var]
def add_client(self, var: Variable, new_client: Tuple[Apply, int]) -> NoReturn:
def add_client(self, var: Variable, new_client: Tuple[Apply, int]) -> None:
"""Update the clients of `var` with `new_clients`.
Parameters
......@@ -250,7 +250,7 @@ class FunctionGraph(MetaObject):
def remove_client(
self, var: Variable, client_to_remove: Tuple[Apply, int], reason: str = None
) -> NoReturn:
) -> None:
"""Recursively removes clients of a variable.
This is the main method to remove variables or `Apply` nodes from
......@@ -316,7 +316,7 @@ class FunctionGraph(MetaObject):
def import_var(
self, var: Variable, reason: str = None, import_missing: bool = False
) -> NoReturn:
) -> None:
"""Import variables into this `FunctionGraph`.
This will also import the `variable`'s `Apply` node.
......@@ -358,7 +358,7 @@ class FunctionGraph(MetaObject):
check: bool = True,
reason: str = None,
import_missing: bool = False,
) -> NoReturn:
) -> None:
"""Recursively import everything between an `Apply` node and the `FunctionGraph`'s outputs.
Parameters:
......@@ -424,7 +424,7 @@ class FunctionGraph(MetaObject):
new_var: Variable,
reason: str = None,
import_missing: bool = False,
) -> NoReturn:
) -> None:
"""Change ``node.inputs[i]`` to `new_var`.
``new_var.type == old_var.type`` must be ``True``, where ``old_var`` is the
......@@ -486,7 +486,7 @@ class FunctionGraph(MetaObject):
reason: str = None,
verbose: bool = None,
import_missing: bool = False,
) -> NoReturn:
) -> None:
"""Replace a variable in the `FunctionGraph`.
This is the main interface to manipulate the subgraph in `FunctionGraph`.
......@@ -547,12 +547,12 @@ class FunctionGraph(MetaObject):
node, i, new_var, reason=reason, import_missing=import_missing
)
def replace_all(self, pairs: List[Tuple[Variable, Variable]], **kwargs) -> NoReturn:
def replace_all(self, pairs: List[Tuple[Variable, Variable]], **kwargs) -> None:
"""Replace variables in the ``FunctionGraph`` according to ``(var, new_var)`` pairs in a list."""
for var, new_var in pairs:
self.replace(var, new_var, **kwargs)
def attach_feature(self, feature: Feature) -> NoReturn:
def attach_feature(self, feature: Feature) -> None:
"""Add a ``graph.features.Feature`` to this function graph and trigger its on_attach callback."""
# Filter out literally identical `Feature`s
if feature in self._features:
......@@ -578,7 +578,7 @@ class FunctionGraph(MetaObject):
# Add the feature
self._features.append(feature)
def remove_feature(self, feature: Feature) -> NoReturn:
def remove_feature(self, feature: Feature) -> None:
"""
Removes the feature from the graph.
......@@ -595,7 +595,7 @@ class FunctionGraph(MetaObject):
if detach is not None:
detach(self)
def execute_callbacks(self, name: str, *args, **kwargs) -> NoReturn:
def execute_callbacks(self, name: str, *args, **kwargs) -> None:
"""Execute callbacks
Calls `getattr(feature, name)(*args)` for each feature which has
......@@ -706,7 +706,7 @@ class FunctionGraph(MetaObject):
ords.setdefault(node, []).extend(prereqs)
return ords
def check_integrity(self) -> NoReturn:
def check_integrity(self) -> None:
"""
Call this for a diagnosis if things go awry.
......
......@@ -18,7 +18,6 @@ from typing import (
ClassVar,
Dict,
List,
NoReturn,
Optional,
Pattern,
Set,
......@@ -51,7 +50,7 @@ ComputeMapType = List[bool]
OutputStorageType = List[Optional[List[Any]]]
ParamsInputType = Optional[Tuple[Any]]
PerformMethodType = Callable[
[Apply, List[Any], OutputStorageType, ParamsInputType], NoReturn
[Apply, List[Any], OutputStorageType, ParamsInputType], None
]
ThunkType = Callable[[PerformMethodType, StorageMapType, ComputeMapType, Apply], Any]
......@@ -380,7 +379,7 @@ class Op(MetaObject):
inputs: List[Variable],
output_storage: OutputStorageType,
params: ParamsInputType = None,
) -> NoReturn:
) -> None:
"""Calculate the function on the inputs and put the variables in the output storage.
Parameters
......@@ -456,7 +455,7 @@ class Op(MetaObject):
storage_map: StorageMapType,
compute_map: ComputeMapType,
impl: Optional[Text],
) -> NoReturn:
) -> None:
"""Make any special modifications that the Op needs before doing `Op.make_thunk`.
This can modify the node inplace and should return nothing.
......@@ -682,7 +681,7 @@ def get_test_value(v: Variable) -> Any:
return v.get_test_value()
def missing_test_message(msg: Text) -> NoReturn:
def missing_test_message(msg: Text) -> None:
"""
Displays msg, a message saying that some test_value is missing,
in the appropriate form based on config.compute_test_value:
......@@ -840,7 +839,7 @@ int main( int argc, const char* argv[] )
)
return default_openmp
def update_self_openmp(self) -> NoReturn:
def update_self_openmp(self) -> None:
"""
Make sure self.openmp is not True if there is no support in gxx.
......@@ -981,7 +980,7 @@ class ExternalCOp(COp):
"and specify the func_name"
)
def load_c_code(self, func_files: List[Text]) -> NoReturn:
def load_c_code(self, func_files: List[Text]) -> None:
"""Loads the C code to perform the `Op`."""
func_files = [self.get_path(f) for f in func_files]
self.func_codes = []
......
......@@ -4,7 +4,7 @@ import ctypes
import platform
import re
from abc import abstractmethod
from typing import Any, NoReturn, Optional, Text, TypeVar, Union
from typing import Any, Optional, Text, TypeVar, Union
from aesara.graph import utils
from aesara.graph.basic import Constant, Variable
......@@ -71,7 +71,7 @@ class Type(MetaObject):
storage: Any,
strict: bool = False,
allow_downcast: Optional[bool] = None,
) -> NoReturn:
) -> None:
"""Return data or an appropriately wrapped/converted data by converting it in-place.
This method allows one to reuse old allocated memory. If this method
......
from abc import ABC, abstractmethod
from copy import copy, deepcopy
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
NoReturn,
Optional,
Set,
Tuple,
Union,
)
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple, Union
from numpy import ndarray
......@@ -32,7 +21,7 @@ if TYPE_CHECKING:
StorageMapType = Dict[Variable, List[Optional[Union[ndarray, slice]]]]
OutputStorageType = List[Optional[List[Any]]]
ThunkType = Tuple[Callable[[], NoReturn], List["Container"], List["Container"]]
ThunkType = Tuple[Callable[[], None], List["Container"], List["Container"]]
class Container:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论