Nimrod Fiat
Nimrod Fiat

Reputation: 483

pylint invalid name error (C0103) doesn't follow python conventions

I have a private variable in a class - _expected_substring_result .
This is the line 26 in my module, which is part of my init function - self._expected_substring_result = _expected_substring_result.

This is the error I'm getting from lint-python - ..\endpoint.py:26:4: C0103: Attribute name "_expected_substring_result" doesn't conform to '[a-z_][a-z0-9_]{0,30}$' pattern (invalid-name) .

This doesn't make sense - a private field in python is supposed to begin with an underscore.
I know how to fix it, by either editing the linter config, or adding # pylint: disable=invalid-name. But this seems too odd an issue to just be something the pylint devs forgot about.

Is this a bug, or am I missing something ?
Thanks,

Upvotes: 1

Views: 1338

Answers (2)

Denis Barmenkov
Denis Barmenkov

Reputation: 2319

pylint 3.0.0-a4 doesn't find your error in this code snippet below. Please provide your __init__ for further investigation :)

class Hi:
    def __init__(self, _expected_substring_result):
        self._expected_substring_result = _expected_substring_result

Upvotes: 1

qouify
qouify

Reputation: 3920

You can give to pylint the format you use for attribute names with the --attr-rgx option. For example to have attribute starting with possibly two underscores:

pylint --attr-rgx=_?_?[a-z0-9]+(_[a-z]+)*_?_?$ ...

Several such naming schemes can be defined: for class names, for module names, ...

You can also edit your pylintrc file to change this parameter.

Upvotes: 3

Related Questions