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