Skip to content

Commit 533a625

Browse files
Heeded pyling warnings
Added module docstring, foxed C0209, W0707, R1735, W0201, W1705
1 parent 62c9be0 commit 533a625

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

dpctl/tensor/_device.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# limitations under the License.
1616
import dpctl
1717

18+
__doc__ = "Implementation of array API mandated Device class"
19+
1820

1921
class Device:
2022
"""
@@ -29,7 +31,8 @@ class Device:
2931
or ``sycl_device``.
3032
"""
3133

32-
__device_queue_map__ = dict()
34+
__device_queue_map__ = {}
35+
sycl_queue_ = None
3336

3437
def __new__(cls, *args, **kwargs):
3538
raise TypeError("No public constructor")
@@ -62,9 +65,9 @@ def create_device(cls, dev):
6265
obj.sycl_queue_ = cls.__device_queue_map__[dev]
6366
else:
6467
raise ValueError(
65-
"Using non-root device {} to specify offloading "
68+
f"Using non-root device {dev} to specify offloading "
6669
"target is ambiguous. Please use dpctl.SyclQueue "
67-
"targeting this device".format(dev)
70+
"targeting this device"
6871
)
6972
else:
7073
if dev is None:
@@ -100,13 +103,13 @@ def sycl_device(self):
100103
def __repr__(self):
101104
try:
102105
sd = self.sycl_device
103-
except AttributeError:
106+
except AttributeError as exc:
104107
raise ValueError(
105-
"Instance of {} is not initialized".format(self.__class__)
106-
)
108+
f"Instance of {self.__class__} is not initialized"
109+
) from exc
107110
try:
108111
fs = sd.filter_string
109-
return "Device({})".format(fs)
112+
return f"Device({fs})"
110113
except TypeError:
111114
# This is a sub-device
112115
return repr(self.sycl_queue)
@@ -150,20 +153,19 @@ def normalize_queue_device(sycl_queue=None, device=None):
150153
if q is None:
151154
d = Device.create_device(d)
152155
return d.sycl_queue
153-
else:
154-
if not isinstance(q, dpctl.SyclQueue):
155-
raise TypeError(f"Expected dpctl.SyclQueue, got {type(q)}")
156-
if d is None:
157-
return q
158-
d = Device.create_device(d)
159-
qq = dpctl.utils.get_execution_queue(
160-
(
161-
q,
162-
d.sycl_queue,
163-
)
156+
if not isinstance(q, dpctl.SyclQueue):
157+
raise TypeError(f"Expected dpctl.SyclQueue, got {type(q)}")
158+
if d is None:
159+
return q
160+
d = Device.create_device(d)
161+
qq = dpctl.utils.get_execution_queue(
162+
(
163+
q,
164+
d.sycl_queue,
165+
)
166+
)
167+
if qq is None:
168+
raise TypeError(
169+
"sycl_queue and device keywords can not be both specified"
164170
)
165-
if qq is None:
166-
raise TypeError(
167-
"sycl_queue and device keywords can not be both specified"
168-
)
169-
return qq
171+
return qq

0 commit comments

Comments
 (0)