8000 Add `Any` return annotation to `__getattr__` methods that return a un… · pytorch/pytorch@c65de03 · GitHub
[go: up one dir, main page]

Skip to content

Commit c65de03

Browse files
rchen152pytorchmergebot
authored andcommitted
Add Any return annotation to __getattr__ methods that return a union of types. (#150204)
Adds an `Any` return type annotation to `__getattr__` methods in `torch/_ops.py` that return a union of types. Attribute access returning a union of types can cause issues downstream because consumers would need to handle all of the possible types to make the type checker happy. This doesn't seem to matter today for mypy, presumably because `Any` is always inferred when a return type annotation is missing, but it still makes explicit what mypy is already doing implicitly. Pull Request resolved: #150204 Approved by: https://github.com/malfet
1 parent dee016c commit c65de03

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

torch/_ops.py

Expand all lines: torch/_ops.py
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def _schemas(self):
10861086
for overload_name in self._overload_names
10871087
}
10881088

1089-
def __getattr__(self, key):
1089+
def __getattr__(self, key) -> Any:
10901090
# It is not a valid op_name when __file__ is passed in
10911091
if key == "__file__":
10921092
return "torch.ops"
@@ -1246,7 +1246,7 @@ def __init__(self, name):
12461246
def __iter__(self):
12471247
return iter(self._dir)
12481248

1249-
def __getattr__(self, op_name):
1249+
def __getattr__(self, op_name) -> Any:
12501250
# It is not a valid op_name when __file__ is passed in
12511251
if op_name == "__file__":
12521252
return "torch.ops"

0 commit comments

Comments
 (0)
0