[Python] Pylint C0103 confusion [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    Here's the MRE (mre.py):

    """
    MRE
    """

    from functools import partial


    def func(_t, _c):
    """
    NOOP
    """


    for i in range(10):
    for j in range(10):
    t = "Exit" if i == 9 and j == 9 else f"{i}, {j}"
    c = partial(func, i, j)


    Then:

    python -m pylint mre.py
    ************* Module mre
    mre.py:16:8: C0103: Constant name "t" doesn't conform to UPPER_CASE naming style (invalid-name)

    -----------------------------------
    Your code has been rated at 8.33/10


    Pylint seems to want the variable t (type str) to be uppercase whereas c (type partial) is OK. If I change t to T, Pylint gives a 10/10 score for this MRE.

    I have tried running Pylint with various --*-naming-style arguments to try to suppress this but to no avail.

    However, this seems inconsistent to me. Why is it OK for c to be lowercase and t not to be lowercase when the context in which they are used is the same? Sure, they're different types but is Pylint seriously suggesting that (local) variables of type str need to be declared as uppercase?

    I don't want to know how to suppress the warning, I want to understand Pylint's rationale.

    Continue reading...

Compartilhe esta Página