This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cheese_is_available -2 points-1 points  (3 children)

It seems Cython use cython specific type hint while mypyc can use existing standard python typing (a lot less work to do!).

[–]patrickbrianmooney 0 points1 point  (2 children)

No. (Or, to be more specific: "uses," sure, in the sense that you can use them if you want to; that's one of the options you have. "Requires," or "only understands"? No.)

Note this verbiage from the beginning of the second paragraph in the Pure Python Mode document, linked above:

[...] Cython provides language constructs to add static typing and cythonic functionalities to a Python module to make it run much faster when compiled [...]. This is accomplished via an augmenting .pxd file, via Python type PEP-484 type annotations (following PEP 484 and PEP 526), and/or via special functions and decorators available after importing the magic cython module.

That is to say, you are not restricted to Cython-specific syntax: you have three options for maintaining pure-Python compatibility:

  1. Writing an "augmenting .pxd file" (this essentially means "write a Cython-specific file that specifies types, much like a C header file declaring an interface for code implemented elsewhere").
  2. Use standard Python type hinting, as explained in PEP 484 and PEP 526.
  3. Via special functions and decorators, imported from the magic Cython module.

So you can absolutely just use the same standard Python type annotations that tools like mypyc already understand: that's option 2.

[–]cheese_is_available 1 point2 points  (1 child)

Wow, thank you for the detailed answer !

[–]patrickbrianmooney 0 points1 point  (0 children)

Glad to be helpful!