Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#953245: pylint: pyreverse fails when parsing dataclasses

6 views
Skip to first unread message

Raphael

unread,
Mar 6, 2020, 8:00:03 AM3/6/20
to
Package: pylint
Version: 2.4.4-2
Severity: normal

Dear Maintainer,

pyreverse fails to parse python code that contains dataclasses. It is simple to reproduce the
problem with a simple python file containing only:

from dataclasses import dataclass
@dataclass
class Data:
a: int

running pyreverse with no option on this file leads to the following error:

parsing pyrevbug.py...
Traceback (most recent call last):
File "/usr/bin/pyreverse", line 11, in <module>
load_entry_point('pylint==2.4.4', 'console_scripts', 'pyreverse')()
File "/usr/lib/python3/dist-packages/pylint/__init__.py", line 37, in run_pyreverse
PyreverseRun(sys.argv[1:])
File "/usr/lib/python3/dist-packages/pylint/pyreverse/main.py", line 184, in __init__
sys.exit(self.run(args))
File "/usr/lib/python3/dist-packages/pylint/pyreverse/main.py", line 202, in run
diadefs = handler.get_diadefs(project, linker)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/diadefslib.py", line 235, in get_diadefs
diagrams = DefaultDiadefGenerator(linker, self).visit(project)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/utils.py", line 217, in visit
self.visit(local_node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/utils.py", line 217, in visit
self.visit(local_node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/utils.py", line 214, in visit
methods[0](node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/diadefslib.py", line 169, in visit_classdef
self.extract_classes(node, anc_level, association_level)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/diadefslib.py", line 113, in extract_classes
self.add_class(klass_node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/diadefslib.py", line 83, in add_class
self.linker.visit(node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/utils.py", line 214, in visit
methods[0](node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/inspector.py", line 166, in visit_classdef
self.handle_assignattr_type(assignattr, node)
File "/usr/lib/python3/dist-packages/pylint/pyreverse/inspector.py", line 232, in handle_assignattr_type
current = set(parent.instance_attrs_type[node.attrname])
AttributeError: 'Unknown' object has no attribute 'attrname'


Note that pyreverse3 of the buster version of pylint3 works correctly.

Cordially,
Raphaël

-- System Information:
Debian Release: bullseye/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (500, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.4.0-4-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE=fr:en_GB (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages pylint depends on:
ii python3 3.7.5-3
ii python3-astroid 2.3.3-1
ii python3-isort 4.3.4+ds1-2
ii python3-logilab-common 1.4.3-2
ii python3-mccabe 0.6.1-3
ii python3-setuptools 44.0.0-1

Versions of packages pylint recommends:
ii python3-tk 3.8.2-2

Versions of packages pylint suggests:
ii pylint-doc 2.4.4-2

-- no debconf information

Takahide Nojima

unread,
Oct 30, 2021, 5:10:03 AM10/30/21
to
Hi Raphaël,

I'm not a maintainer of the pylint package, but I just let you know
about your bug report.

This problem, as you reported, seems to resolve since pylint 2.5.0 in
the upstream.
FYI: https://github.com/PyCQA/pylint/issues/3256

Moreover, Debian stable (bullseye) already has a newer version of
pylint, more than 2.5.0 at this moment. Then I believe the maintainer
has resolved this problem.

To confirm your problem today, I got the correct results shown below.
(Sorry for accuracy, I use Debian sid.)

--------------here-----------------
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux bookworm/sid
Release: unstable
Codename: sid
$ env LANG=C dpkg -l pylint
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-
aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-
======================================================
ii pylint 2.7.2-3 all Python 3 code static
checker and UML diagram generator
$ cat dataclass.py
from dataclasses import dataclass
@dataclass
class Data:
a: int
$ pyreverse dataclass
parsing /home/nojima/prog/python-test/pylint-work/bugs/dataclass.py...
$ ls
classes.dot dataclass.py
------------here-----------------------------


I hope this will be for your help.

Takahide Nojima
0 new messages