Skip to content

Commit

Permalink
Merge pull request #11940 from joshiayush/DefaultDevice_exit
Browse files Browse the repository at this point in the history
Reformat `DefaultDevice.__exit__()` to include type hints for `exc_type`, `exc_val`, and `exc_tb`
  • Loading branch information
MuhammadSaeedBatikh authored Mar 8, 2023
2 parents 99de718 + c4c1682 commit bfb44de
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ivy/functional/ivy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import math
import psutil
import pynvml
from typing import Optional, Tuple
import types
from typing import Type, Optional, Tuple

# noinspection PyUnresolvedReferences
try:
Expand Down Expand Up @@ -80,19 +81,30 @@ def __enter__(self):
ivy.set_default_device(self._dev)
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> Union[ivy.Device, str]:
def __exit__(self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[Type[BaseException]],
exc_tb: Optional[types.TracebackType]) -> Union[ivy.Device, str]:
"""
Exit the runtime context related to the specified device.
Parameters
----------
exc_type
The type of the exception that was raised.
exc_val
The exception that was raised.
exc_tb
The traceback of the exception that was raised.
Returns
-------
ret
Self, an instance of the same class.
If no exception was raised, returns an instance of the same class.
Examples
--------
A "gpu" as device:
>>> with ivy.DefaultDevice("gpu") as device:
>>> pass
>>> # after with block device.__exit__() is called
Expand Down

0 comments on commit bfb44de

Please sign in to comment.