Monday, May 23, 2016

Duplicate function definition in Python

I discovered that Python will happily allow two functions with the same signature to be declared in the same file without any warning.  The second function will just replace the first one.  It seems like this should give a compile error or warning, but maybe there are some use cases where it would be useful to redefine/override a function based on a condition, so the compiler can't determine whether the duplicate function definition is valid.

pylint will provide a "function-redefined" error if it detects a duplicate function, so it seems this is not a generally good practice.