pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.31k stars 1.14k forks source link

Different Linting output for different python minor version #8451

Open bushwhackr opened 1 year ago

bushwhackr commented 1 year ago

Question

Given

a.py

"""
Module header
"""
from typing import Union

ObjectT = Union[str, int]
ObjectTa = Union[str, int]

Running pylint in python 3.10 results in an error:

************* Module a
a.py:6:0: C0103: Type alias name "ObjectT" doesn't conform to predefined naming style (invalid-name)

Running pylint in python 3.8 does not lead to an error at all.


python 3.10 env

root@8a4f80953c93:/featurebyte# python --version
Python 3.10.10
root@8a4f80953c93:/featurebyte# poetry show pylint
 name         : pylint
 version      : 2.17.0
 description  : python code static checker

dependencies
 - astroid >=2.15.0,<=2.17.0-dev0
 - colorama >=0.4.5
 - dill >=0.2
 - isort >=4.2.5,<6
 - mccabe >=0.6,<0.8
 - platformdirs >=2.2.0
 - tomli >=1.1.0
 - tomlkit >=0.10.1
 - typing-extensions >=3.10.0

python 3.8 env

 root@b1ee16e05463:/featurebyte# python --version
Python 3.8.16
root@b1ee16e05463:/featurebyte# poetry show pylint
 name         : pylint
 version      : 2.17.0
 description  : python code static checker

dependencies
 - astroid >=2.15.0,<=2.17.0-dev0
 - colorama >=0.4.5
 - dill >=0.2
 - isort >=4.2.5,<6
 - mccabe >=0.6,<0.8
 - platformdirs >=2.2.0
 - tomli >=1.1.0
 - tomlkit >=0.10.1
 - typing-extensions >=3.10.0

Documentation for future user

Maybe a direct reference to the PEP.

Additional context

No response

mbyrnepr2 commented 1 year ago

Thanks @bushwhackr for the report; I can reproduce this. inferred.qname() on this line of Pylint code is .Union on Python 3.10 but it is ._SpecialForm on Python 3.8.

mbyrnepr2 commented 1 year ago

Pinging @DanielNoord because I notice you worked on this checker :) Do you think, to simplify things, the checker should focus solely on explicit type aliases? In theory a valid type alias can assign to any type: https://docs.python.org/3/library/typing.html#type-aliases

DanielNoord commented 1 year ago

I removed checking of Callables somewhere during the creation of the checker as it created false positives. I would be in favour of expanding the check to also cover ._SpecialForm and see what the primer tells us.