PyCQA/pylint
syntax-error incorectly detected inside a type-comment with python 3.8 #3556
exhuma posted onGitHub
Steps to reproduce
"requirements.txt" file for the code-example below:
astroid==2.4.0
attrs==19.3.0
autopep8==1.5.2
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
mypy==0.770
mypy-extensions==0.4.3
psutil==5.7.0
psycopg2-binary==2.8.5
pycodestyle==2.5.0
pylint==2.5.0
six==1.14.0
SQLAlchemy==1.3.16
sqlalchemy-stubs==0.3
toml==0.10.0
typed-ast==1.4.1
typing-extensions==3.7.4.2
wrapt==1.12.1
Create a file with the following content:
# pylint: disable=too-few-public-methods, missing-docstring
from typing import Set
from sqlalchemy import Column, ForeignKeyConstraint, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
Base = declarative_base()
class Device(Base): # type: ignore
__tablename__ = 'device'
hostname = Column(String, primary_key=True)
ports = relationship( # type: Set[Port]
"Port",
back_populates="device",
collection_class=set
)
class Port(Base): # type: ignore
__tablename__ = 'port'
__table_args__ = (
ForeignKeyConstraint(
['hostname'],
['device.hostname'],
ondelete='CASCADE',
onupdate='CASCADE',
),
)
hostname = Column(String, primary_key=True)
label = Column(String, primary_key=True)
device = relationship( # type: Device
"Device",
back_populates="ports",
uselist=False,
)
Run pylint on that file.
Current behavior
pylint currently raises a syntax-error on line 14:
************* Module model
samemory/model.py:14:36: E0001: invalid syntax (<unknown>, line 14) (syntax-error)
Expected behavior
No syntax error should be raised
pylint --version output
āŗ poetry run pylint --version ā: 2
/usr/lib/python3.8/site-packages/html5lib/_trie/_base.py:3: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
from collections import Mapping
/home/exhuma/work/sandbox/samemorytest/.venv/lib/python3.8/site-packages/astroid/interpreter/_import/spec.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
pylint 2.5.0
astroid 2.4.0
Python 3.8.2 (default, Feb 26 2020, 22:21:03)
[GCC 9.2.1 20200130]