compile - arnthor89/pygame GitHub Wiki
compile
Description
The function compiles cursor strings into cursor data. It takes a set of strings with equal length and computes the binary data for that cursor. It takes black and white arguments that are single letter strings that tells which characters represent black pixels, and which characters represent white pixels. All other characters are considered clear.
It returns a tuple containing the cursor data and cursor mask data. Both these arguments are used when setting a cursor with pygame.mouse.set_cursor().
Complexity
The reason for the high complexity in the function is that the function does a lot of argument checking in the beginning. Additionally, the for loop contains multiple if statements.
Refactoring strategy
A simple way to decrease the CC would be to split the function into smaller functions. Firstly, all the argument checks in the beginning of the function could be put in a separate function called compile_check_arguments. Secondly, the content of the for loop could be put in a separate function called compile_get_color. This function could take the symbol and return which color it should have.