Skip to content

Commit db8186b

Browse files
expland the explanation with an example and reword
1 parent 2ea3971 commit db8186b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

cuda_bindings/docs/source/tips_and_tricks.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@ There is an important distinction between the ``getPtr()`` method and the behavi
1212
Getting and setting attributes of extension types
1313
=================================================
1414

15-
While the bindings outwardly presents the attributes of extension types in a Pythonic way, they can't always be interacted with in a Pythonic style. Often the getters/setters (__getitem__(), __setitem__()) are actually a translation step to convert values between Python and C. For example, in some cases, attempting to modify an attribute in place, will lead to unexpected behavior due to the constraints of the underlying implementation. For this reason, users should use the getters and setters directly when interacting with extension types.
15+
While the bindings outwardly presents the attributes of extension types in a Pythonic way, they can't always be interacted with in a Pythonic style. Often the getters/setters (__getitem__(), __setitem__()) are actually a translation step to convert values between Python and C. For example, in some cases, attempting to modify an attribute in place, will lead to unexpected behavior due to the design of the underlying implementation. For this reason, users should use the getters and setters directly when interacting with extension types.
16+
17+
An example of this is the :class:`~cuda.bindings.driver.CULaunchConfig` type.
18+
19+
.. code-block:: python
20+
21+
cfg = cuda.CUlaunchConfig()
22+
23+
cfg.numAttrs += 1
24+
attr = cuda.CUlaunchAttribute()
25+
26+
...
27+
28+
# This works. We are passing the attribute to the setter
29+
drv_cfg.attrs = [attr]
30+
31+
# This does not work. We are trying to modify the attribute in place
32+
drv_cfg.attrs.append(attr)
33+

0 commit comments

Comments
 (0)