diff options
author | da-woods <dw-git@d-woods.co.uk> | 2023-04-20 19:05:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 19:05:29 +0100 |
commit | f570f8dec0565ef820d888f837645b2ae3b681fa (patch) | |
tree | c660f8b844a36486728c86a70019e84769dfe9e6 | |
parent | cfb9973aff60fe01747020de94bb30c0e306c5bd (diff) | |
download | cython-f570f8dec0565ef820d888f837645b2ae3b681fa.tar.gz |
[docs] Table for annotation typing rules (#4887)
* [docs] Table for annotation typing rules
* Add back "tips and tricks"
* Move table into an external csv
It's much easier to maintain there, while editing rst tables
is a real pain
* Update docs/src/tutorial/annotation_typing_table.csv
* Update docs/src/tutorial/pure.rst
Co-authored-by: scoder <stefan_ml@behnel.de>
---------
Co-authored-by: scoder <stefan_ml@behnel.de>
-rw-r--r-- | docs/src/tutorial/annotation_typing_table.csv | 9 | ||||
-rw-r--r-- | docs/src/tutorial/pure.rst | 13 |
2 files changed, 22 insertions, 0 deletions
diff --git a/docs/src/tutorial/annotation_typing_table.csv b/docs/src/tutorial/annotation_typing_table.csv new file mode 100644 index 000000000..43c48b1ab --- /dev/null +++ b/docs/src/tutorial/annotation_typing_table.csv @@ -0,0 +1,9 @@ +Feature ,Cython 0.29 ,Cython 3.0 +``int``,Any Python object,Exact Python ``int`` (``language_level=3`` only) +``float``,,C ``double`` +"Builtin type e.g. ``dict``, ``list`` ",,"Exact type (no subclasses), not ``None``" +Extension type defined in Cython ,,"Specified type or a subclasses, not ``None``" +"``cython.int``, ``cython.long``, etc. ",,Equivalent C numeric type +``typing.Optional[any_type]``,Not supported,"Specified type (which must be a Python object), allows ``None``" +``typing.List[any_type]`` (and similar) ,Not supported,"Exact ``list``, with the element type ignored currently " +``typing.ClassVar[...]`` ,Not supported,Python-object class variable (when used in a class definition) diff --git a/docs/src/tutorial/pure.rst b/docs/src/tutorial/pure.rst index 53d6f9528..32a7fa0ca 100644 --- a/docs/src/tutorial/pure.rst +++ b/docs/src/tutorial/pure.rst @@ -419,6 +419,19 @@ efficient C code. In other cases, however, where the generated C code could benefit from these type hints but does not currently, help is welcome to improve the type analysis in Cython. +Reference table +^^^^^^^^^^^^^^^ + +The following reference table documents how type annotations are currently interpreted. +Cython 0.29 behaviour is only shown where it differs from Cython 3.0 behaviour. +The current limitations will likely be lifted at some point. + +.. csv-table:: Annotation typing rules + :file: annotation_typing_table.csv + :header-rows: 1 + :class: longtable + :widths: 1 1 1 + Tips and Tricks --------------- |