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

unsubscriptable-object with type[int] on Python 3.9 #4001

Closed
SuperStormer opened this issue Dec 30, 2020 · 4 comments · Fixed by PennyDreadfulMTG/Penny-Dreadful-Tools#8447
Closed

Comments

@SuperStormer
Copy link

PEP585 specifies that type implements __class_getitem__, yet pylint still errors. However, this does not occur with other PEP585 types such as list or tuple, which I believe was previously fixed. type also needs to be fixed in the same way.

Steps to reproduce

  1. Create file a.py:
a: type[int] = int
  1. Run pylint --rcfile=/dev/null a.py

Current behavior

************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
a.py:1:3: E1136: Value 'type' is unsubscriptable (unsubscriptable-object)

----------------------------------------------------------------------
Your code has been rated at -50.00/10 (previous run: -50.00/10, +0.00)

Expected behavior

Only the missing-module-docstring line should be printed, not the unsubscriptable-object.

pylint --version output

Installed via pip install git+https://github.com/PyCQA/pylint/ git+https://github.com/PyCQA/astroid
pylint commit b3b8ed2
astroid commit 99d9c77cc276b1c5f5d76d91282d05b5df3a2c21

pylint 2.6.1-dev1
astroid 2.5.0
Python 3.9.1 (default, Dec  8 2020, 07:51:42)
[GCC 10.2.0]
@hippo91
Copy link
Contributor

hippo91 commented Dec 30, 2020

@SuperStormer thanks for your report. I can reproduce it.
The problem seems to come form the fact that in python3.9 the type object has no __class_getitem__ method whereas, for example, listobject has one.

In [7]: type.__class_getitem__
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-00c2935419fa> in <module>
----> 1 type.__class_getitem__

AttributeError: type object 'type' has no attribute '__class_getitem__'

In [8]: list.__class_getitem__
Out[8]: <function list.__class_getitem__>

@hippo91
Copy link
Contributor

hippo91 commented Dec 30, 2020

@PCManticore i think we would need an astroid brain to handle this. What do you think about it? By the way is it possible and a good idea to enable a brain for a specific python version?

@PCManticore
Copy link
Contributor

@hippo91 Yes, it's definitely a good idea to add a brain just for a given Python version.

@hippo91
Copy link
Contributor

hippo91 commented Jan 23, 2021

This issue should be solved by pylint-dev/astroid#883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants