/usr/share/doc/python-sip-doc/html/_sources/annotations.rst.txt is in python-sip-doc 4.19.7+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 | Annotations
===========
In this section we describe each of the annotations that can be used in
specification files.
Annotations can either be :ref:`argument annotations <ref-arg-annos>`,
:ref:`class annotations <ref-class-annos>`, :ref:`mapped type annotations
<ref-mapped-type-annos>`, :ref:`enum annotations <ref-enum-annos>`,
:ref:`exception annotations <ref-exception-annos>`, :ref:`function annotations
<ref-function-annos>`, :ref:`typedef annotations <ref-typedef-annos>` or
:ref:`variable annotations <ref-variable-annos>` depending on the context in
which they can be used.
Annotations are placed between forward slashes (``/``). Multiple annotations
are comma separated within the slashes.
Annotations have a type and, possibly, a value. The type determines the
format of the value. The name of an annotation and its value are separated by
``=``.
Annotations can have one of the following types:
*boolean*
This type of annotation has no value and is implicitly true.
*integer*
This type of annotation is an integer. In some cases the value is
optional.
*name*
The value is a name that is compatible with a C/C++ identifier. In some
cases the value is optional.
*dotted name*
The value is a name that is compatible with an identifier preceded by a
Python scope.
*string*
The value is a double quoted string.
*API range*
The value is the name of an API (defined using the :directive:`%API`
directive) separated by a range of version numbers with a colon.
The range of version numbers is a pair of numbers separated by a hyphen
specifying the lower and upper bounds of the range. A version number is
within the range if it is greater or equal to the lower bound and less
than the upper bound. Each bound can be omitted meaning that the range is
unbounded in that direction.
For example::
# This is part of the PyQt4 API up to but excluding v2.
void hex() /API=PyQt4:-2/
# This is part of the PyQt4 API starting from v2.
void hex() /PyName=hex_, API=PyQt4:2-/
The following example shows argument and function annotations::
void exec(QWidget * /Transfer/) /ReleaseGIL, PyName=call_exec/;
.. _ref-arg-annos:
Argument Annotations
--------------------
.. argument-annotation:: AllowNone
This boolean annotation specifies that the value of the corresponding
argument (which should be either :stype:`SIP_PYBUFFER`,
:stype:`SIP_PYCALLABLE`, :stype:`SIP_PYDICT`, :stype:`SIP_PYLIST`,
:stype:`SIP_PYSLICE`, :stype:`SIP_PYTUPLE` or :stype:`SIP_PYTYPE`) may be
``None``.
.. argument-annotation:: Array
This boolean annotation specifies that the corresponding argument refers
to an array.
The argument should be either a pointer to a wrapped type, a ``char *`` or
a ``unsigned char *``. If the argument is a character array then the
annotation also implies the :aanno:`Encoding` annotation with an encoding
of ``"None"``.
There must be a corresponding argument with the :aanno:`ArraySize`
annotation specified. The annotation may only be specified once in a list
of arguments.
.. argument-annotation:: ArraySize
This boolean annotation specifies that the corresponding argument (which
should be either ``short``, ``unsigned short``, ``int``, ``unsigned``,
``long`` or ``unsigned long``) refers to the size of an array. There must
be a corresponding argument with the :aanno:`Array` annotation specified.
The annotation may only be specified once in a list of arguments.
.. argument-annotation:: Constrained
Python will automatically convert between certain compatible types. For
example, if a floating pointer number is expected and an integer supplied,
then the integer will be converted appropriately. This can cause problems
when wrapping C or C++ functions with similar signatures. For example::
// The wrapper for this function will also accept an integer argument
// which Python will automatically convert to a floating point number.
void foo(double);
// The wrapper for this function will never get used.
void foo(int);
This boolean annotation specifies that the corresponding argument (which
should be either ``bool``, ``int``, ``float``, ``double``, ``enum`` or a
wrapped class) must match the type without any automatic conversions. In
the context of a wrapped class the invocation of any
:directive:`%ConvertToTypeCode` is suppressed.
The following example gets around the above problem::
// The wrapper for this function will only accept floating point
// numbers.
void foo(double /Constrained/);
// The wrapper for this function will be used for anything that Python
// can convert to an integer, except for floating point numbers.
void foo(int);
Any type hint for the argument will be ignored.
.. argument-annotation:: DisallowNone
.. versionadded:: 4.16.4
This boolean annotation specifies that the value of the corresponding
argument (which should be a pointer to either a C++ class or a mapped type)
must not be ``None``.
.. argument-annotation:: DocType
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :aanno:`TypeHint` annotation instead.
This string annotation specifies the type of the argument as it will appear
in any generated docstrings. It is usually used with arguments of type
:stype:`SIP_PYOBJECT` to provide a more specific type.
.. argument-annotation:: DocValue
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :aanno:`TypeHintValue` annotation instead.
This string annotation specifies the default value of the argument as it
will appear in any generated docstrings.
.. argument-annotation:: Encoding
This string annotation specifies that the corresponding argument (which
should be either ``char``, ``const char``, ``char *`` or ``const char *``)
refers to an encoded character or ``'\0'`` terminated encoded string with
the specified encoding. The encoding can be either ``"ASCII"``,
``"Latin-1"``, ``"UTF-8"`` or ``"None"``. An encoding of ``"None"`` means
that the corresponding argument refers to an unencoded character or string.
The default encoding is specified by the :directive:`%DefaultEncoding`
directive. If the directive is not specified then ``None`` is used.
Python v3 will use the ``bytes`` type to represent the argument if the
encoding is ``"None"`` and the ``str`` type otherwise.
Python v2 will use the ``str`` type to represent the argument if the
encoding is ``"None"`` and the ``unicode`` type otherwise.
.. argument-annotation:: GetWrapper
This boolean annotation is only ever used in conjunction with handwritten
code specified with the :directive:`%MethodCode` directive. It causes an
extra variable to be generated for the corresponding argument which is a
pointer to the Python object that wraps the argument.
See the :directive:`%MethodCode` directive for more detail.
.. argument-annotation:: In
This boolean annotation is used to specify that the corresponding argument
(which should be a pointer type) is used to pass a value to the function.
For pointers to wrapped C structures or C++ class instances, ``char *`` and
``unsigned char *`` then this annotation is assumed unless the :aanno:`Out`
annotation is specified.
For pointers to other types then this annotation must be explicitly
specified if required. The argument will be dereferenced to obtain the
actual value.
Both :aanno:`In` and :aanno:`Out` may be specified for the same argument.
.. argument-annotation:: KeepReference
This optional integer annotation is used to specify that a reference to the
corresponding argument should be kept to ensure that the object is not
garbage collected. If the method is called again with a new argument then
the reference to the previous argument is discarded. Note that ownership
of the argument is not changed.
If the function is a method then the reference is kept by the instance,
i.e. ``self``. Therefore the extra reference is released when the instance
is garbage collected.
If the function is a class method or an ordinary function and it is
annotated using the :fanno:`Factory` annotation, then the reference is
kept by the object created by the function. Therefore the extra reference
is released when that object is garbage collected.
Otherwise the reference is not kept by any specific object and will never
be released.
If a value is specified then it defines the argument's key. Arguments of
different constructors or methods that have the same key are assumed to
refer to the same value.
.. argument-annotation:: NoCopy
.. versionadded:: 4.10.1
This boolean annotation is used with arguments of virtual methods that are
a ``const`` reference to a class. Normally, if the class defines a copy
constructor then a copy of the returned reference is automatically created
and wrapped before being passed to a Python reimplementation of the method.
The copy will be owned by Python. This means that the reimplementation may
take a reference to the argument without having to make an explicit copy.
If the annotation is specified then the copy is not made and the original
reference is wrapped instead and will be owned by C++.
.. argument-annotation:: Out
This boolean annotation is used to specify that the corresponding argument
(which should be a pointer type) is used by the function to return a value
as an element of a tuple.
For pointers to wrapped C structures or C++ class instances, ``char *`` and
``unsigned char *`` then this annotation must be explicitly specified if
required.
For pointers to other types then this annotation is assumed unless the
:aanno:`In` annotation is specified.
Both :aanno:`In` and :aanno:`Out` may be specified for the same argument.
.. argument-annotation:: PyInt
.. versionadded:: 4.12
This boolean annotation is used with ``char``, ``signed char`` and
``unsigned char`` arguments to specify that they should be interpreted as
integers rather than strings of one character.
.. argument-annotation:: ResultSize
This boolean annotation is used with functions or methods that return a
``void *`` or ``const void *``. It identifies an argument that defines the
size of the block of memory whose address is being returned. This allows
the :class:`sip.voidptr` object that wraps the address to support the
Python buffer protocol.
.. argument-annotation:: SingleShot
.. deprecated:: 4.18
This boolean annotation is used only with arguments of type
:stype:`SIP_RXOBJ_CON` to specify that the signal connected to the slot
will only ever be emitted once. This prevents a certain class of memory
leaks.
.. argument-annotation:: Transfer
This boolean annotation is used to specify that ownership of the
corresponding argument (which should be a wrapped C structure or C++ class
instance) is transferred from Python to C++. In addition, if the argument
is of a class method, then it is associated with the class instance with
regard to the cyclic garbage collector.
If the annotation is used with the :aanno:`Array` annotation then the
array of pointers to the sequence of C structures or C++ class instances
that is created on the heap is not automatically freed.
See :ref:`ref-object-ownership` for more detail.
.. argument-annotation:: TransferBack
This boolean annotation is used to specify that ownership of the
corresponding argument (which should be a wrapped C structure or C++ class
instance) is transferred back to Python from C++. In addition, any
association of the argument with regard to the cyclic garbage collector
with another instance is removed.
See :ref:`ref-object-ownership` for more detail.
.. argument-annotation:: TransferThis
This boolean annotation is only used in C++ constructors or methods. In
the context of a constructor or factory method it specifies that ownership
of the instance being created is transferred from Python to C++ if the
corresponding argument (which should be a wrapped C structure or C++ class
instance) is not ``None``. In addition, the newly created instance is
associated with the argument with regard to the cyclic garbage collector.
In the context of a non-factory method it specifies that ownership of
``this`` is transferred from Python to C++ if the corresponding argument is
not ``None``. If it is ``None`` then ownership is transferred to Python.
The annotation may be used more that once, in which case ownership is
transferred to last instance that is not ``None``.
See :ref:`ref-object-ownership` for more detail.
.. argument-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type of the argument as it will appear
in any generated docstrings and PEP 484 type hints. It is the equivalent
of specifying :aanno:`TypeHintIn` and :aanno:`TypeHintOut` with the same
value. It is usually used with arguments of type :stype:`SIP_PYOBJECT` to
provide a more specific type.
.. argument-annotation:: TypeHintIn
.. versionadded:: 4.18
This string annotation specifies the type of the argument as it will appear
in any generated docstrings and PEP 484 type hints when the argument is
used to pass a value to a function (rather than being used to return a
value from a function). It is usually used with arguments of type
:stype:`SIP_PYOBJECT` to provide a more specific type.
.. argument-annotation:: TypeHintOut
.. versionadded:: 4.18
This string annotation specifies the type of the argument as it will appear
in any generated docstrings and PEP 484 type hints when the argument is
used to return a value from a function (rather than being used to pass a
value to a function). It is usually used with arguments of type
:stype:`SIP_PYOBJECT` to provide a more specific type.
.. argument-annotation:: TypeHintValue
.. versionadded:: 4.18
This string annotation specifies the default value of the argument as it
will appear in any generated docstrings.
.. _ref-class-annos:
Class Annotations
-----------------
.. class-annotation:: Abstract
This boolean annotation is used to specify that the class has additional
pure virtual methods that have not been specified and so it cannot be
instantiated or sub-classed from Python. It should not be specified if all
pure virtual methods have been specified.
.. class-annotation:: AllowNone
.. versionadded:: 4.8.2
Normally when a Python object is converted to a C/C++ instance ``None``
is handled automatically before the class's
:directive:`%ConvertToTypeCode` is called. This boolean annotation
specifies that the handling of ``None`` will be left to the
:directive:`%ConvertToTypeCode`. The annotation is ignored if the class
does not have any :directive:`%ConvertToTypeCode`.
.. class-annotation:: API
.. versionadded:: 4.9
This API range annotation is used to specify an API and corresponding
range of version numbers that the class is enabled for.
If a class or mapped type has different implementations enabled for
different ranges of version numbers then those ranges must not overlap.
Note that sub-classing from a class that has different implementations is
not currently supported.
See :ref:`ref-incompat-apis` for more detail.
.. class-annotation:: DelayDtor
This boolean annotation is used to specify that the class's destructor
should not be called until the Python interpreter exits. It would normally
only be applied to singleton classes.
When the Python interpreter exits the order in which any wrapped instances
are garbage collected is unpredictable. However, the underlying C or C++
instances may need to be destroyed in a certain order. If this annotation
is specified then when the wrapped instance is garbage collected the C or
C++ instance is not destroyed but instead added to a list of delayed
instances. When the interpreter exits then the function
:c:func:`sipDelayedDtors()` is called with the list of delayed instances.
:c:func:`sipDelayedDtors()` can then choose to call (or ignore) the
destructors in any desired order.
The :c:func:`sipDelayedDtors()` function must be specified using the
:directive:`%ModuleCode` directive.
.. c:function:: void sipDelayedDtors(const sipDelayedDtor *dd_list)
:param dd_list:
the linked list of delayed instances.
.. c:type:: sipDelayedDtor
This structure describes a particular delayed destructor.
.. c:member:: const char* dd_name
This is the name of the class excluding any package or module name.
.. c:member:: void* dd_ptr
This is the address of the C or C++ instance to be destroyed. It's
exact type depends on the value of :c:member:`dd_isderived`.
.. c:member:: int dd_isderived
This is non-zero if the type of :c:member:`dd_ptr` is actually the
generated derived class. This allows the correct destructor to be
called. See :ref:`ref-derived-classes`.
.. c:member:: sipDelayedDtor* dd_next
This is the address of the next entry in the list or zero if this is
the last one.
Note that the above applies only to C and C++ instances that are owned by
Python.
.. class-annotation:: Deprecated
This boolean annotation is used to specify that the class is deprecated.
It is the equivalent of annotating all the class's constructors, function
and methods as being deprecated.
.. class-annotation:: FileExtension
.. versionadded:: 4.16.6
This string annotation is used to specify the filename extension to be used
for the file containing the generated code for this class. A separate file
will be generated even if the :option:`-j <sip -j>` command line option is
specified.
.. class-annotation:: ExportDerived
.. versionadded:: 4.15
In many cases SIP generates a derived class for each class being wrapped
(see :ref:`ref-derived-classes`). Normally this is used internally. This
boolean annotation specifies that the declaration of the class is exported
and able to be used by handwritten code.
.. class-annotation:: External
This boolean annotation is used to specify that the class is defined in
another module. Declarations of external classes are private to the module
in which they appear.
.. class-annotation:: Metatype
This dotted name annotation specifies the name of the Python type object
(i.e. the value of the ``tp_name`` field) used as the meta-type used when
creating the type object for this C structure or C++ type.
See the section :ref:`ref-types-metatypes` for more details.
.. class-annotation:: Mixin
.. versionadded:: 4.15
This boolean annotation specifies that the class can be used as a mixin
with other wrapped classes.
Normally a Python application cannot define a new class that is derived
from more than one wrapped class. In C++ this would create a new C++
class. This cannot be done from Python. At best a C++ instance of each of
the wrapped classes can be created and wrapped as separate Python objects.
However some C++ classes may function perfectly well with this restriction.
Such classes are often intended to be used as mixins.
If this annotation is specified then a separate instance of the class is
created. The main instance automatically delegates to the instance of the
mixin when required. A mixin class should have the following
characteristics:
- Any constructor arguments should be able to be specified using keyword
arguments.
- The class should not have any virtual methods.
.. class-annotation:: NoDefaultCtors
This boolean annotation is used to suppress the automatic generation of
default constructors for the class.
.. class-annotation:: NoTypeHint
.. versionadded:: 4.18
This boolean annotation is used to suppress the generation of the PEP 484
type hint for the class and its contents.
.. class-annotation:: PyName
This name annotation specifies an alternative name for the class being
wrapped which is used when it is referred to from Python. It is required
when a class name is the same as a Python keyword. It may also be used to
avoid name clashes with other objects (e.g. enums, exceptions, functions)
that have the same name in the same C++ scope.
.. seealso:: :directive:`%AutoPyName`
.. class-annotation:: Supertype
This dotted name annotation specifies the name of the Python type object
(i.e. the value of the ``tp_name`` field) used as the super-type used when
creating the type object for this C structure or C++ type.
See the section :ref:`ref-types-metatypes` for more details.
.. class-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type of the class as it will appear
in any generated docstrings and PEP 484 type hints. It is the equivalent
of specifying :canno:`TypeHintIn` and :canno:`TypeHintOut` with the same
value.
.. class-annotation:: TypeHintIn
.. versionadded:: 4.18
This string annotation specifies the type of the class as it will appear
in any generated docstrings and PEP 484 type hints when an instance of the
class is passed as an argument to a function (rather than being returned
from a function). It is usually used with classes that implement
:directive:`%ConvertToTypeCode` to allow additional types to be used
whenever an instance of the class is expected.
.. class-annotation:: TypeHintOut
.. versionadded:: 4.18
This string annotation specifies the type of the class as it will appear
in any generated docstrings and PEP 484 type hints when an instance of the
class is returned from a function (rather than being used to pass a
value to a function).
.. class-annotation:: TypeHintValue
.. versionadded:: 4.18
This string annotation specifies the default value of the class as it will
appear in any generated docstrings.
.. class-annotation:: VirtualErrorHandler
.. versionadded:: 4.14
This name annotation specifies the handler (defined by the
:directive:`%VirtualErrorHandler` directive) that is called when a Python
re-implementation of any of the class's virtual C++ functions raises a
Python exception. If not specified then the handler specified by the
``default_VirtualErrorHandler`` argument of the :directive:`%Module`
directive is used.
.. seealso:: :fanno:`NoVirtualErrorHandler`, :fanno:`VirtualErrorHandler`, :directive:`%VirtualErrorHandler`
.. _ref-mapped-type-annos:
Mapped Type Annotations
-----------------------
.. mapped-type-annotation:: AllowNone
Normally when a Python object is converted to a C/C++ instance ``None``
is handled automatically before the mapped type's
:directive:`%ConvertToTypeCode` is called. This boolean annotation
specifies that the handling of ``None`` will be left to the
:directive:`%ConvertToTypeCode`.
.. mapped-type-annotation:: API
.. versionadded:: 4.9
This API range annotation is used to specify an API and corresponding
range of version numbers that the mapped type is enabled for.
If a class or mapped type has different implementations enabled for
different ranges of version numbers then those ranges must not overlap.
It should not be used with mapped type templates.
See :ref:`ref-incompat-apis` for more detail.
.. mapped-type-annotation:: DocType
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :manno:`TypeHint` annotation instead.
This string annotation serves the same purpose as the :aanno:`DocType`
argument annotation when applied to the mapped type being defined.
.. mapped-type-annotation:: NoRelease
This boolean annotation is used to specify that the mapped type does not
support the :c:func:`sipReleaseType()` function. Any
:directive:`%ConvertToTypeCode` should not create temporary instances of
the mapped type, i.e. it should not return :c:macro:`SIP_TEMPORARY`.
.. mapped-type-annotation:: PyName
This name annotation specifies an alternative name for the mapped type
being wrapped which is used when it is referred to from Python. The only
time a Python type is created for a mapped type is when it is used as a
scope for static methods or enums.
It should not be used with mapped type templates.
.. seealso:: :directive:`%AutoPyName`
.. mapped-type-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type of the mapped type as it will
appear in any generated docstrings and PEP 484 type hints. It is the
equivalent of specifying :manno:`TypeHintIn` and :manno:`TypeHintOut` with
the same value.
.. mapped-type-annotation:: TypeHintIn
.. versionadded:: 4.18
This string annotation specifies the type of the mapped type as it will
appear in any generated docstrings and PEP 484 type hints when it is passed
to a function (rather than being returned from a function).
.. mapped-type-annotation:: TypeHintOut
.. versionadded:: 4.18
This string annotation specifies the type of the mapped type as it will
appear in any generated docstrings and PEP 484 type hints when it is
returned from a function (rather than being passed to a function).
.. mapped-type-annotation:: TypeHintValue
.. versionadded:: 4.18
This string annotation specifies the default value of the mapped type as it
will appear in any generated docstrings.
.. _ref-enum-annos:
Enum Annotations
----------------
.. enum-annotation:: NoScope
.. versionadded:: 4.15
This boolean annotation specifies the that scope of an enum's members
should be omitted in the generated code. Normally this would mean that the
generated code will not compile. However it is useful when defining
pseudo-enums, for example, to wrap global values so that they are defined
(in Python) within the scope of a class.
.. enum-annotation:: NoTypeHint
.. versionadded:: 4.18
This boolean annotation is used to suppress the generation of the PEP 484
type hint for the enum or enum member.
.. enum-annotation:: PyName
This name annotation specifies an alternative name for the enum or enum
member being wrapped which is used when it is referred to from Python. It
is required when an enum or enum member name is the same as a Python
keyword. It may also be used to avoid name clashes with other objects
(e.g. classes, exceptions, functions) that have the same name in the same
C++ scope.
.. seealso:: :directive:`%AutoPyName`
.. _ref-exception-annos:
Exception Annotations
---------------------
.. exception-annotation:: Default
This boolean annotation specifies that the exception being defined will be
used as the default exception to be caught if a function or constructor
does not have a ``throw`` clause.
.. exception-annotation:: PyName
This name annotation specifies an alternative name for the exception being
defined which is used when it is referred to from Python. It is required
when an exception name is the same as a Python keyword. It may also be
used to avoid name clashes with other objects (e.g. classes, enums,
functions) that have the same name.
.. seealso:: :directive:`%AutoPyName`
.. _ref-function-annos:
Function Annotations
--------------------
.. function-annotation:: AbortOnException
.. versionadded:: 4.16.4
This boolean annotation specifies that when a Python re-implementation of a
virtual C++ function raises a Python exception then ``abort()`` is
called after the error handler returns.
.. function-annotation:: AllowNone
.. versionadded:: 4.16.4
This boolean annotation is used to specify that the value returned by the
function (which should be either :stype:`SIP_PYBUFFER`,
:stype:`SIP_PYCALLABLE`, :stype:`SIP_PYDICT`, :stype:`SIP_PYLIST`,
:stype:`SIP_PYSLICE`, :stype:`SIP_PYTUPLE` or :stype:`SIP_PYTYPE`) may be
``None``.
.. function-annotation:: API
.. versionadded:: 4.9
This API range annotation is used to specify an API and corresponding
range of version numbers that the function is enabled for.
See :ref:`ref-incompat-apis` for more detail.
.. function-annotation:: AutoGen
This optional name annotation is used with class methods to specify that
the method be automatically included in all sub-classes. The value is the
name of a feature (specified using the :directive:`%Feature` directive)
which must be enabled for the method to be generated.
.. function-annotation:: Default
This boolean annotation is only used with C++ constructors. Sometimes SIP
needs to create a class instance. By default it uses a constructor with no
compulsory arguments if one is specified. (SIP will automatically generate
a constructor with no arguments if no constructors are specified.) This
annotation is used to explicitly specify which constructor to use. Zero is
passed as the value of any arguments to the constructor. This annotation
is ignored if the class defines :directive:`%InstanceCode`.
.. function-annotation:: Deprecated
This boolean annotation is used to specify that the constructor or function
is deprecated. A deprecation warning is issued whenever the constructor or
function is called.
.. function-annotation:: DisallowNone
.. versionadded:: 4.16.4
This boolean annotation is used to specify that the value returned by the
function (which should be a pointer to either a C++ class or a mapped type)
must not be ``None``.
.. function-annotation:: DocType
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :fanno:`TypeHint` annotation instead.
This string annotation serves the same purpose as the :aanno:`DocType`
argument annotation when applied to the type of the value returned by the
function.
.. function-annotation:: Encoding
This string annotation serves the same purpose as the :aanno:`Encoding`
argument annotation when applied to the type of the value returned by the
function.
.. function-annotation:: Factory
This boolean annotation specifies that the value returned by the function
(which should be a wrapped C structure or C++ class instance) is a newly
created instance and is owned by Python.
See :ref:`ref-object-ownership` for more detail.
.. function-annotation:: HoldGIL
This boolean annotation specifies that the Python Global Interpreter Lock
(GIL) is not released before the call to the underlying C or C++ function.
See :ref:`ref-gil` and the :fanno:`ReleaseGIL` annotation.
.. function-annotation:: __imatmul__
.. versionadded:: 4.17
This boolean annotation specifies that a ``__imatmul__()`` method should be
automatically generated that will use the method being annotated to compute
the value that the ``__imatmul__()`` method will return.
.. function-annotation:: KeepReference
.. versionadded:: 4.12.2
This optional integer annotation serves the same purpose as the
:aanno:`KeepReference` argument annotation when applied to the type of the
value returned by the function.
If the function is a class method or an ordinary function then the
reference is not kept by any other object and so the returned value will
never be garbage collected.
.. function-annotation:: KeywordArgs
.. versionadded:: 4.10
This string annotation specifies the level of support the argument parser
generated for this function will provide for passing the parameters using
Python's keyword argument syntax. The value of the annotation can be
either ``"None"`` meaning that keyword arguments are not supported,
``"All"`` meaning that all named arguments can be passed as keyword
arguments, or ``"Optional"`` meaning that all named optional arguments
(i.e. those with a default value) can be passed as keyword arguments.
If the annotation is not used then the value specified by the
``keyword_arguments`` argument of the :directive:`%Module` directive is
used.
Keyword arguments cannot be used for functions that use an ellipsis to
designate that the function has a variable number of arguments.
.. deprecated:: 4.12
It can also be used as a boolean annotation which is the equivalent of
specifiying a value of ``"All"``.
.. function-annotation:: __len__
.. versionadded:: 4.10.3
This boolean annotation specifies that a ``__len__()`` method should be
automatically generated that will use the method being annotated to compute
the value that the ``__len__()`` method will return.
.. function-annotation:: __matmul__
.. versionadded:: 4.17
This boolean annotation specifies that a ``__matmul__()`` method should be
automatically generated that will use the method being annotated to compute
the value that the ``__matmul__()`` method will return.
.. function-annotation:: NewThread
This boolean annotation specifies that the function (which must be a
virtual) will be executed in a new thread.
.. function-annotation:: NoArgParser
This boolean annotation is used with methods and global functions to
specify that the supplied :directive:`%MethodCode` will handle the parsing
of the arguments.
.. function-annotation:: NoCopy
.. versionadded:: 4.10.1
This boolean annotation is used with methods and global functions that
return a ``const`` reference to a class. Normally, if the class defines a
copy constructor then a copy of the returned reference is automatically
created and wrapped. The copy will be owned by Python.
If the annotation is specified then the copy is not made and the original
reference is wrapped instead and will be owned by C++.
.. function-annotation:: NoDerived
This boolean annotation is only used with C++ constructors. In many cases
SIP generates a derived class for each class being wrapped (see
:ref:`ref-derived-classes`). This derived class contains constructors with
the same C++ signatures as the class being wrapped. Sometimes you may want
to define a Python constructor that has no corresponding C++ constructor.
This annotation is used to suppress the generation of the constructor in
the derived class.
.. function-annotation:: NoKeywordArgs
.. versionadded:: 4.10
.. deprecated:: 4.12
Use the :fanno:`KeywordArgs` annotation with a value of ``"None"``.
This boolean annotation specifies that the argument parser generated for
this function will not support passing the parameters using Python's
keyword argument syntax. In other words, the argument parser will only
support normal positional arguments. This annotation is useful when the
default setting of allowing keyword arguments has been changed via the
command line or the :directive:`%Module` directive, but you would still
like certain functions to only support positional arguments.
.. function-annotation:: NoRaisesPyException
.. versionadded:: 4.13.1
This boolean annotation specifies that the function or constructor does not
raise a Python exception to indicate that an error occurred.
.. seealso:: :fanno:`RaisesPyException`
.. function-annotation:: NoTypeHint
.. versionadded:: 4.18
This boolean annotation is used to suppress the generation of the PEP 484
type hint for the function or constructor.
.. function-annotation:: NoVirtualErrorHandler
.. versionadded:: 4.14
This boolean annotation specifies that when a Python re-implementation of a
virtual C++ function raises a Python exception then ``PyErr_Print()`` is
always called. Any error handler specified by either the
:fanno:`VirtualErrorHandler` function annotation, the
:canno:`VirtualErrorHandler` class annotation or the
``default_VirtualErrorHandler`` argument of the :directive:`%Module`
directive is ignored.
.. seealso:: :fanno:`VirtualErrorHandler`, :canno:`VirtualErrorHandler`, :directive:`%VirtualErrorHandler`
.. function-annotation:: Numeric
This boolean annotation specifies that the operator should be interpreted
as a numeric operator rather than a sequence operator.
Python uses the ``+`` operator for adding numbers and concatanating
sequences, and the ``*`` operator for multiplying numbers and repeating
sequences. Unless this or the :fanno:`Sequence` annotation is specified,
SIP tries to work out which is meant by looking at other operators that
have been defined for the type. If it finds either ``-``, ``-=``, ``/``,
``/=``, ``%`` or ``%=`` defined then it assumes that ``+``, ``+=``, ``*``
and ``*=`` should be numeric operators. Otherwise, if it finds either
``[]``, :meth:`__getitem__`, :meth:`__setitem__` or :meth:`__delitem__`
defined then it assumes that they should be sequence operators.
.. function-annotation:: PostHook
This name annotation is used to specify the name of a Python builtin that
is called immediately after the call to the underlying C or C++ function or
any handwritten code. The builtin is not called if an error occurred. It
is primarily used to integrate with debuggers.
.. function-annotation:: PreHook
This name annotation is used to specify the name of a Python builtin that
is called immediately after the function's arguments have been successfully
parsed and before the call to the underlying C or C++ function or any
handwritten code. It is primarily used to integrate with debuggers.
.. function-annotation:: PyName
This name annotation specifies an alternative name for the function being
wrapped which is used when it is referred to from Python. It is required
when a function or method name is the same as a Python keyword. It may
also be used to avoid name clashes with other objects (e.g. classes, enums,
exceptions) that have the same name in the same C++ scope.
.. seealso:: :directive:`%AutoPyName`
.. function-annotation:: PyInt
.. versionadded:: 4.12
This boolean annotation serves the same purpose as the :aanno:`PyInt`
argument annotation when applied to the type of the value returned by the
function.
.. function-annotation:: RaisesPyException
.. versionadded:: 4.12.1
This boolean annotation specifies that the function or constructor raises a
Python exception to indicate that an error occurred. Any current exception
is cleared before the function or constructor is called. It is ignored if
the :directive:`%MethodCode` directive is used.
.. seealso:: :fanno:`NoRaisesPyException`
.. function-annotation:: ReleaseGIL
This boolean annotation specifies that the Python Global Interpreter Lock
(GIL) is released before the call to the underlying C or C++ function and
reacquired afterwards. It should be used for functions that might block or
take a significant amount of time to execute. See :ref:`ref-gil` and the
:fanno:`HoldGIL` annotation.
.. function-annotation:: Sequence
.. versionadded:: 4.14.7
This boolean annotation specifies that the operator should be interpreted
as a sequence operator rather than a numeric operator.
Python uses the ``+`` operator for adding numbers and concatanating
sequences, and the ``*`` operator for multiplying numbers and repeating
sequences. Unless this or the :fanno:`Numeric` annotation is specified,
SIP tries to work out which is meant by looking at other operators that
have been defined for the type. If it finds either ``-``, ``-=``, ``/``,
``/=``, ``%`` or ``%=`` defined then it assumes that ``+``, ``+=``, ``*``
and ``*=`` should be numeric operators. Otherwise, if it finds either
``[]``, :meth:`__getitem__`, :meth:`__setitem__` or :meth:`__delitem__`
defined then it assumes that they should be sequence operators.
.. function-annotation:: Transfer
This boolean annotation specifies that ownership of the value returned by
the function (which should be a wrapped C structure or C++ class instance)
is transferred to C++. It is only used in the context of a class
constructor or a method.
In the case of methods returned values (unless they are new references to
already wrapped values) are normally owned by C++ anyway. However, in
addition, an association between the returned value and the instance
containing the method is created with regard to the cyclic garbage
collector.
See :ref:`ref-object-ownership` for more detail.
.. function-annotation:: TransferBack
This boolean annotation specifies that ownership of the value returned by
the function (which should be a wrapped C structure or C++ class instance)
is transferred back to Python from C++. Normally returned values (unless
they are new references to already wrapped values) are owned by C++. In
addition, any association of the returned value with regard to the cyclic
garbage collector with another instance is removed.
See :ref:`ref-object-ownership` for more detail.
.. function-annotation:: TransferThis
This boolean annotation specifies that ownership of ``this`` is transferred
from Python to C++.
See :ref:`ref-object-ownership` for more detail.
.. function-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type of the value returned by the
function as it will appear in any generated docstrings and PEP 484 type
hints. It is usually used with results of type :stype:`SIP_PYOBJECT` to
provide a more specific type.
.. function-annotation:: VirtualErrorHandler
.. versionadded:: 4.14
This name annotation specifies the handler (defined by the
:directive:`%VirtualErrorHandler` directive) that is called when a Python
re-implementation of the virtual C++ function raises a Python exception.
If not specified then the handler specified by the class's
:canno:`VirtualErrorHandler` is used.
.. seealso:: :fanno:`NoVirtualErrorHandler`, :canno:`VirtualErrorHandler`, :directive:`%VirtualErrorHandler`
.. _ref-typedef-annos:
Typedef Annotations
-------------------
.. typedef-annotation:: Capsule
.. versionadded:: 4.14.1
This boolean annotation may only be used when the base type is ``void *``
and specifies that a Python capsule object is used to wrap the value rather
than a :class:`sip.voidptr`. The advantage of using a capsule is that name
based type checking is performed using the name of the type being defined.
For versions of Python that do not support capules :class:`sip.voidptr` is
used instead and name based type checking is not performed.
.. typedef-annotation:: DocType
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :tanno:`TypeHint` annotation instead.
This string annotation serves the same purpose as the :aanno:`DocType`
argument annotation when applied to the mapped type being defined.
.. typedef-annotation:: Encoding
This string annotation serves the same purpose as the :aanno:`Encoding`
argument annotation when applied to the mapped type being defined.
.. typedef-annotation:: NoTypeName
This boolean annotation specifies that the definition of the type rather
than the name of the type being defined should be used in the generated
code.
Normally a typedef would be defined as follows::
typedef bool MyBool;
This would result in ``MyBool`` being used in the generated code.
Specifying the annotation means that ``bool`` will be used in the generated
code instead.
.. typedef-annotation:: PyInt
.. versionadded:: 4.12
This boolean annotation serves the same purpose as the :aanno:`PyInt`
argument annotation when applied to the type being defined.
.. typedef-annotation:: PyName
.. versionadded:: 4.13.1
This name annotation only applies when the typedef is being used to create
the wrapping for a class defined using a template and specifies an
alternative name for the class when it is referred to from Python. It is
required when a class name is the same as a Python keyword. It may also
be used to avoid name clashes with other objects (e.g. enums, exceptions,
functions) that have the same name in the same C++ scope.
.. seealso:: :directive:`%AutoPyName`
.. typedef-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type as it will appear in any
generated docstrings and PEP 484 type hints. It is the equivalent of
specifying :tanno:`TypeHintIn` and :tanno:`TypeHintOut` with the same
value.
.. typedef-annotation:: TypeHintIn
.. versionadded:: 4.18
This string annotation specifies the type as it will appear in any
generated docstrings and PEP 484 type hints when it is passed to a function
(rather than being returned from a function). It is usually used with
arguments of type :stype:`SIP_PYOBJECT` to provide a more specific type.
.. typedef-annotation:: TypeHintOut
.. versionadded:: 4.18
This string annotation specifies the type as it will appear in any
generated docstrings and PEP 484 type hints when it is returned from a
function (rather than being passed to a function). It is usually used with
arguments of type :stype:`SIP_PYOBJECT` to provide a more specific type.
.. _ref-variable-annos:
Variable Annotations
--------------------
.. variable-annotation:: DocType
.. versionadded:: 4.10
.. deprecated:: 4.18
Use the :vanno:`TypeHint` annotation instead.
This string annotation serves the same purpose as the :aanno:`DocType`
argument annotation when applied to the type of the variable being defined.
.. variable-annotation:: Encoding
This string annotation serves the same purpose as the :aanno:`Encoding`
argument annotation when applied to the type of the variable being defined.
.. variable-annotation:: NoSetter
.. versionadded:: 4.16
This boolean annotation specifies that the variable will have no setter and
will be read-only. Because SIP does not fully understand C/C++ types
(particularly ``const`` arrays) it is sometimes necessary to explicitly
annotate a variable as being read-only.
.. variable-annotation:: NoTypeHint
.. versionadded:: 4.18
This boolean annotation is used to suppress the generation of the PEP 484
type hint for the variable.
.. variable-annotation:: PyInt
.. versionadded:: 4.12
This boolean annotation serves the same purpose as the :aanno:`PyInt`
argument annotation when applied to the type of the variable being defined.
.. variable-annotation:: PyName
This name annotation specifies an alternative name for the variable being
wrapped which is used when it is referred to from Python. It is required
when a variable name is the same as a Python keyword. It may also be used
to avoid name clashes with other objects (e.g. classes, functions) that
have the same name in the same C++ scope.
.. seealso:: :directive:`%AutoPyName`
.. variable-annotation:: TypeHint
.. versionadded:: 4.18
This string annotation specifies the type of the variable as it will appear
in any generated docstrings and PEP 484 type hints. It is usually used
with arguments of type :stype:`SIP_PYOBJECT` to provide a more specific
type.
|