pyccel.naming.pythonnameclashchecker module#

Handles name clash problems in Python

class pyccel.naming.pythonnameclashchecker.PythonNameClashChecker(self)[source]#

Bases: LanguageNameClashChecker

Class containing functions to help avoid problematic names in Python.

A class which provides functionalities to check or propose variable names and verify that they do not cause name clashes. Name clashes may arise when generating names for new variables.

get_collisionless_name(name, symbols)[source]#

Get a valid name which doesn’t collision with symbols.

Find a new name based on the suggested name which does not appear in the provided symbols. It is not necessary to exclude keywords for names which were either originally valid Python names, or internally generated names.

Parameters:
  • name (str) – The suggested name.

  • symbols (set) – Symbols which should be considered as collisions.

Returns:

A new name which is collision free.

Return type:

str

has_clash(name, symbols)[source]#

Indicate whether the proposed name causes any clashes.

Indicate whether the proposed name causes any clashes by comparing it with the reserved keywords and the symbols which are already defined in the scope.

Parameters:
  • name (str) – The proposed name.

  • symbols (set of str) – The symbols already used in the scope.

Returns:

True if the name clashes with an existing name. False otherwise.

Return type:

bool

keywords = {}#