wiki:Dev/Technical/CodeCaveats

Version 2 (modified by dmartinc, 3 years ago) (diff)

dont use built-ins as variable names

Code Caveats

This section's aim is to log some tricks and caveats that you should take into consideration while developing for Indico.

1. Usage of .getUser() within a management area

Don't assume that a user is always logged in just because he is in the management area of an event. getUser() can return None because the user could have used a modification key to login. So, always check that getUser() is not None.


2. Do not use Python built-ins as variable names

This is more a general Python programming tip, but most people fall into it some time or another.

Try not to use Python built-in keywords, such as "type", "list", "dict", "vars", etc. as variable names.

Example of problem:

def mymethod(self, value, type):
    self._type = type
    ...
    if type(value) is int: #we try to use Python's built-in type function to check the type of an object
        ...

This will fail because we have redefined type when using it as a function argument; so the built-in "type" function is no longer available.

Using PyLint helps detect these problems.