pyccel.codegen.printing.pycode module#

Module containing the PythonCodePrinter class which is responsible for printing Pyccel’s AST in Python. This is used to print the .pyi files which are generated alongside the translated code. These files contain type annotations which are used by type checkers and IDEs to provide better support for the generated code. The PythonCodePrinter is also used to print the code for inline functions and interfaces which are not translated but must be available in Python for the translated code to work, as well as to simply print Python code for the tests.

class pyccel.codegen.printing.pycode.PythonCodePrinter(filename, *, verbose)[source]View on GitHub#

Bases: CodePrinter

A printer for printing code in Python.

A printer to convert Pyccel’s AST to strings of Python code. As for all printers the navigation of this file is done via _print_X functions.

Parameters:
  • filename (str) – The name of the file being pyccelised.

  • verbose (int) – The level of verbosity.

get_type_checks(arg_code, class_type)[source]View on GitHub#

Get the code to check if an argument has the expected type.

Get the code to check if an argument has the expected type. This is used in an if block to select the right code to run.

Parameters:
  • arg_code (str) – The code describing the argument being checked.

  • class_type (PyccelType) – The expected type.

Returns:

A list containing the checks that must be satisfied for the type to be considered matching.

Return type:

list[str]

language = 'python'#
printmethod = '_pycode'#