Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent block starting line behaviour for classes #10199

Open
cwiede opened this issue Jan 22, 2025 · 1 comment
Open

Inconsistent block starting line behaviour for classes #10199

cwiede opened this issue Jan 22, 2025 · 1 comment
Labels
Bug 🪲 Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc.

Comments

@cwiede
Copy link

cwiede commented Jan 22, 2025

Bug description

"""
docstring
"""

class FOO: # pylint: disable=invalid-name
    """
    docstring
    """

    def camelCase(self):
        "docstring"
        return

    def good_function(self):
        "docstring"
        return

class BAR(FOO): # pylint: disable=invalid-name
    """
    docstring
    """

    def camelCase2(self):
        "docstring"
        return

    def good_function2(self):
        "docstring"
        return

Configuration

Command used

pylint a.py

Pylint output

************* Module test_pylint
test_pylint.py:23:4: C0103: Method name "camelCase2" doesn't conform to snake_case naming style (invalid-name)

Expected behavior

It is surprising for me that the invalid name is only outputted for the method BAR.camelCase2 and not for method FOO.camelCase. From the documentation I read

If the violation occurs on a block starting line, then it applies only to that line

and so I would expect that the disable=invalid-name statements only apply to the single lines where the classes are defined and not to the whole block of the class.

Pylint version

pylint 3.3.3
astroid 3.3.8
Python 3.13.1 (main, Jan 14 2025, 22:47:35) [MSC v.1942 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

astroid==3.3.8
colorama==0.4.6
dill==0.3.9
isort==5.13.2
mccabe==0.7.0
platformdirs==4.3.6
pylint==3.3.3
tomlkit==0.13.2
@cwiede cwiede added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 22, 2025
@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc. and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 23, 2025
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue.

The message control doc doesn't really talk about scope for classes which is why I added a need specification label so we define how to suppress a message for a whole class.

I thought it was:

class Fruit:
    # pylint: disable=my-message
    ...

But it seems that someone thought that this made sense and implemented it (or maybe the underlying ast implicitly makes it work that way, I didn't look in detail):

class Fruit: # pylint: disable=my-message
    ...

In any case there's an inconsistency right now for class vs inherited class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc.
Projects
None yet
Development

No branches or pull requests

2 participants