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

False unsubscriptable-object positive with generic subprocess.Popen and __future__ annotations #4369

Closed
scop opened this issue Apr 17, 2021 · 1 comment · Fixed by #6536
Closed
Assignees
Labels
C: unsubscriptable-object Issues related to 'unsubscriptable-object' check False Positive 🦟 A message is emitted but nothing is wrong with the code typing
Milestone

Comments

@scop
Copy link
Contributor

scop commented Apr 17, 2021

A variant of #4034, just with annotations imported on python 3.8. Per that issue, outputting the error is arguably correct if the from __future__ import annotations import is not present, but when it is, this should not result in an error.

I'm guessing (not tested) just adding subprocess.Popen to pylint.checkers.utils.SUBSCRIPTABLE_CLASSES_PEP585 would be a quick and dirty fix, but subprocess.Popen isn't actually mentioned in PEP 585 so it wouldn't feel quite right.

There might be some others similarly affected, mypy docs at https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime mention os.PathLike and queue.Queue.

Steps to reproduce

from __future__ import annotations
from subprocess import Popen, PIPE

def foo(popen: Popen[str]) -> None:
    pass

foo(Popen(["ls"], stdout=PIPE))

Current behavior

t4.py:5:15: E1136: Value 'Popen' is unsubscriptable (unsubscriptable-object)

Expected behavior

No unsubscriptable-object

pylint --version output

Result of pylint --version output:

pylint 2.7.4
astroid 2.5.3
Python 3.8.0 (default, Mar 30 2021, 18:43:10) 
[GCC 9.3.0]
 
@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels May 13, 2021
@cdce8p cdce8p added typing and removed Bug 🪲 labels Oct 17, 2021
@cdce8p cdce8p added the C: unsubscriptable-object Issues related to 'unsubscriptable-object' check label Jan 30, 2022
@Avasam
Copy link

Avasam commented Feb 12, 2022

I'm not entirely certain if related, but I'm having the same issue with Column type from` the sqlalchemy typestubs
pylint 2.12.2
Python 3.9.6

from __future__ import annotations
from sqlalchemy import Column, DateTime, Integer, String

class Player(BaseModel):
    __tablename__ = "player"

    user_id = db.Column(db.String(8), primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    # The biggest region code I found so far was "us/co/coloradosprings" at 21
    country_code = db.Column(db.String(24))
    score = db.Column(db.Integer, nullable=False)
    score_details = db.Column(db.String())
    last_update = db.Column(db.DateTime())
    rank: Optional[int] = None

    schedules = db.relationship("Schedule", back_populates="owner")

    @overload
    def __init__(  # type: ignore
        self,
        user_id: str | Column[String],
        name: str | Column[String],
        country_code: Optional[str | Column[String]],
        score: int | float | Column[Integer],
        last_update: Optional[str | Column[DateTime]],
        score_details: Optional[str | Column[String]] = ...,
        rank: Optional[int] = ...
    ): ...
    
[...]

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unsubscriptable-object Issues related to 'unsubscriptable-object' check False Positive 🦟 A message is emitted but nothing is wrong with the code typing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants