Skip to content

Commit f5e1b7b

Browse files
address pylint>=3.2 issues (#757)
* address pylint>=3.2 issues * use name instead of number * Minor tweaks to pylint fixes --------- Co-authored-by: Andreas Kloeckner <[email protected]>
1 parent e421c82 commit f5e1b7b

File tree

6 files changed

+74
-61
lines changed

6 files changed

+74
-61
lines changed

pyopencl/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ def image_init(self, context, flags, format, shape=None, pitches=None,
979979
else:
980980
raise ValueError("images cannot have more than three dimensions")
981981

982-
desc = ImageDescriptor()
982+
desc = ImageDescriptor() \
983+
# pylint: disable=possibly-used-before-assignment
983984

984985
desc.image_type = image_type
985986
desc.shape = shape # also sets desc.array_size
@@ -1354,7 +1355,8 @@ def svmptr_as_buffer(self, ctx: Context, *, flags: Optional[int] = None,
13541355
svm_old_init = SVM.__init__
13551356

13561357
def svm_init(self, mem):
1357-
svm_old_init(self, mem)
1358+
if get_cl_header_version() >= (2, 0):
1359+
svm_old_init(self, mem)
13581360

13591361
self.mem = mem
13601362

pyopencl/algorithm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,9 @@ def __call__(self, queue, n_objects, *args, **kwargs):
12251225
info_record.compressed_indices = cl.array.empty(
12261226
queue, (n_objects + 1,), index_dtype, allocator=allocator)
12271227
info_record.compressed_indices[0] = 0
1228-
compress_events[name] = compress_kernel(
1228+
1229+
compress_events[name] = compress_kernel( \
1230+
# pylint: disable=possibly-used-before-assignment
12291231
info_record.starts,
12301232
compressed_counts,
12311233
info_record.nonempty_indices,

pyopencl/bitonic_sort.py

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def sort_b_prepare_wl(self, argsort, key_dtype, idx_dtype, shape, axis):
225225
elif inc >= 0:
226226
letter = "B2"
227227
ninc = 1
228+
else:
229+
raise AssertionError("Should not happen")
228230

229231
nthreads = size >> ninc
230232

pyopencl/tools.py

+60-56
Original file line numberDiff line numberDiff line change
@@ -348,96 +348,98 @@ def _monkeypatch_svm_docstrings():
348348

349349
# {{{ PooledSVM
350350

351-
PooledSVM.__doc__ = """
352-
An object representing a :class:`SVMPool`-based allocation of
353-
:ref:`svm`. Analogous to :class:`~pyopencl.SVMAllocation`, however once
354-
this object is deleted, its associated device memory is returned to the
355-
pool from which it came.
351+
PooledSVM.__doc__ = ( # pylint: disable=possibly-used-before-assignment
352+
"""An object representing a :class:`SVMPool`-based allocation of
353+
:ref:`svm`. Analogous to :class:`~pyopencl.SVMAllocation`, however once
354+
this object is deleted, its associated device memory is returned to the
355+
pool from which it came.
356356
357-
.. versionadded:: 2022.2
357+
.. versionadded:: 2022.2
358358
359-
.. note::
359+
.. note::
360360
361-
If the :class:`SVMAllocator` for the :class:`SVMPool` that allocated an
362-
object of this type is associated with an (in-order)
363-
:class:`~pyopencl.CommandQueue`, sufficient synchronization is provided
364-
to ensure operations enqueued before deallocation complete before
365-
operations from a different use (possibly in a different queue) are
366-
permitted to start. This applies when :class:`release` is called and
367-
also when the object is freed automatically by the garbage collector.
361+
If the :class:`SVMAllocator` for the :class:`SVMPool` that allocated an
362+
object of this type is associated with an (in-order)
363+
:class:`~pyopencl.CommandQueue`, sufficient synchronization is provided
364+
to ensure operations enqueued before deallocation complete before
365+
operations from a different use (possibly in a different queue) are
366+
permitted to start. This applies when :class:`release` is called and
367+
also when the object is freed automatically by the garbage collector.
368368
369-
Is a :class:`pyopencl.SVMPointer`.
369+
Is a :class:`pyopencl.SVMPointer`.
370370
371-
Supports structural equality and hashing.
371+
Supports structural equality and hashing.
372372
373-
.. automethod:: release
373+
.. automethod:: release
374374
375-
Return the held memory to the pool. See the note about synchronization
376-
behavior during deallocation above.
375+
Return the held memory to the pool. See the note about synchronization
376+
behavior during deallocation above.
377377
378-
.. automethod:: enqueue_release
378+
.. automethod:: enqueue_release
379379
380-
Synonymous to :meth:`release`, for consistency with
381-
:class:`~pyopencl.SVMAllocation`. Note that, unlike
382-
:meth:`pyopencl.SVMAllocation.enqueue_release`, specifying a queue
383-
or events to be waited for is not supported.
380+
Synonymous to :meth:`release`, for consistency with
381+
:class:`~pyopencl.SVMAllocation`. Note that, unlike
382+
:meth:`pyopencl.SVMAllocation.enqueue_release`, specifying a queue
383+
or events to be waited for is not supported.
384384
385-
.. automethod:: bind_to_queue
385+
.. automethod:: bind_to_queue
386386
387-
Analogous to :meth:`pyopencl.SVMAllocation.bind_to_queue`.
387+
Analogous to :meth:`pyopencl.SVMAllocation.bind_to_queue`.
388388
389-
.. automethod:: unbind_from_queue
389+
.. automethod:: unbind_from_queue
390390
391-
Analogous to :meth:`pyopencl.SVMAllocation.unbind_from_queue`.
392-
"""
391+
Analogous to :meth:`pyopencl.SVMAllocation.unbind_from_queue`.
392+
""")
393393

394394
# }}}
395395

396396
# {{{ SVMAllocator
397397

398-
SVMAllocator.__doc__ = """
399-
.. versionadded:: 2022.2
398+
SVMAllocator.__doc__ = ( # pylint: disable=possibly-used-before-assignment
399+
"""
400+
.. versionadded:: 2022.2
400401
401-
.. automethod:: __init__
402+
.. automethod:: __init__
402403
403-
:arg flags: See :class:`~pyopencl.svm_mem_flags`.
404-
:arg queue: If not specified, allocations will be freed
405-
eagerly, irrespective of whether pending/enqueued operations
406-
are still using the memory.
404+
:arg flags: See :class:`~pyopencl.svm_mem_flags`.
405+
:arg queue: If not specified, allocations will be freed
406+
eagerly, irrespective of whether pending/enqueued operations
407+
are still using the memory.
407408
408-
If specified, deallocation of memory will be enqueued
409-
with the given queue, and will only be performed
410-
after previously-enqueue operations in the queue have
411-
completed.
409+
If specified, deallocation of memory will be enqueued
410+
with the given queue, and will only be performed
411+
after previously-enqueue operations in the queue have
412+
completed.
412413
413-
It is an error to specify an out-of-order queue.
414+
It is an error to specify an out-of-order queue.
414415
415-
.. warning::
416+
.. warning::
416417
417-
Not specifying a queue will typically lead to undesired
418-
behavior, including crashes and memory corruption.
419-
See the warning in :ref:`svm`.
418+
Not specifying a queue will typically lead to undesired
419+
behavior, including crashes and memory corruption.
420+
See the warning in :ref:`svm`.
420421
421-
.. automethod:: __call__
422+
.. automethod:: __call__
422423
423-
Return a :class:`~pyopencl.SVMAllocation` of the given *size*.
424-
"""
424+
Return a :class:`~pyopencl.SVMAllocation` of the given *size*.
425+
""")
425426

426427
# }}}
427428

428429
# {{{ SVMPool
429430

430-
SVMPool.__doc__ = remove_common_indentation("""
431-
A memory pool for OpenCL device memory in :ref:`SVM <svm>` form.
432-
*allocator* must be an instance of :class:`SVMAllocator`.
431+
SVMPool.__doc__ = ( # pylint: disable=possibly-used-before-assignment
432+
remove_common_indentation("""
433+
A memory pool for OpenCL device memory in :ref:`SVM <svm>` form.
434+
*allocator* must be an instance of :class:`SVMAllocator`.
433435
434-
.. versionadded:: 2022.2
436+
.. versionadded:: 2022.2
435437
436-
.. automethod:: __init__
437-
.. automethod:: __call__
438+
.. automethod:: __init__
439+
.. automethod:: __call__
438440
439-
Return a :class:`PooledSVM` of the given *size*.
440-
""") + _MEMPOOL_IFACE_DOCS
441+
Return a :class:`PooledSVM` of the given *size*.
442+
""") + _MEMPOOL_IFACE_DOCS)
441443

442444
# }}}
443445

@@ -1363,6 +1365,8 @@ def vec_arg_factory(typename, name):
13631365
parsed_arg = arg
13641366
elif isinstance(arg, tuple):
13651367
parsed_arg = ScalarArg(self.parse_type(arg[0]), arg[1])
1368+
else:
1369+
raise TypeError("unexpected argument type: %s" % type(arg))
13661370

13671371
parsed_args.append(parsed_arg)
13681372

test/test_array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1146,12 +1146,12 @@ def test_slice(ctx_factory):
11461146
a = a_gpu.get()
11471147
b = b_gpu.get()
11481148

1149+
start_offset = 0
1150+
11491151
if queue.device.platform.name == "Intel(R) OpenCL":
11501152
pytest.skip("Intel CL regularly crashes on this test case "
11511153
"-- https://github.com/conda-forge/"
11521154
"intel-compiler-repack-feedstock/issues/7")
1153-
else:
1154-
start_offset = 0
11551155

11561156
from random import randrange
11571157
for _i in range(20):

test/test_wrapper.py

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ def do_test(cl_obj, info_cls, func=None, try_attr_form=True):
163163
& cl.command_queue_properties.PROFILING_ENABLE):
164164
profiling = True
165165
props = cl.command_queue_properties.PROFILING_ENABLE
166+
else:
167+
profiling = False
168+
166169
queue = cl.CommandQueue(ctx,
167170
properties=props)
168171
do_test(queue, cl.command_queue_info)

0 commit comments

Comments
 (0)