dodona
dodona copied to clipboard
Python linter gives unhelpful info message
When defining a method in Python with a name which (presumably) doesn't match this regex [_A-Za-z0-9]{1,30}$, the following info message is shown:

This happens when the name of the function is longer than 30 characters (like in the case above), or when the function contains Unicode characters outside the ASCII range:

The same results can be observed for constants:

Class names seem to be exempt from the maximum length:

... but do not tolerate non-ASCII characters, interestingly, the message here is similar but more informative, which makes me suspect that this is in fact a bug:

This regex check appears to only exist for Python, as both JavaScript and C do not give info messages for the same function names:


The Python docs say this about valid identifiers:
Within the ASCII range (U+0001..U+007F), the valid characters for identifiers are the same as in Python 2.x: the uppercase and lowercase letters A through Z, the underscore _ and, except for the first character, the digits 0 through 9. Python 3.0 introduces additional characters from outside the ASCII range (see PEP 3131). For these characters, the classification uses the version of the Unicode Character Database as included in the unicodedata module. Identifiers are unlimited in length. Case is significant.
Therefore, the regex [_A-Za-z0-9]{1,30}$ matches with all valid Python identifiers except for those that
- Contain non-ASCII characters, but this is already handled by the other check
- Are longer than 30 characters
Therefore, wouldn't it make more sense to replace the regex with one like this ^.{1,30}$ and change the info message to something like Function/Constant/... name should not be longer than 30 characters? This would be a more helpful message, and would also prevent showing two messages when a non-ASCII character is used in an identifier.
We use pylint under the hood to generate these messages. We do a few customizations to it, but generally try to avoid it to ease upgrading. I will look into this at pylint's repo on monday.