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

Regression in Astroid version 2.15.7 in handling subscriptable type parameters #2305

Closed
behnazh-w opened this issue Sep 25, 2023 · 2 comments · Fixed by #2307
Closed

Regression in Astroid version 2.15.7 in handling subscriptable type parameters #2305

behnazh-w opened this issue Sep 25, 2023 · 2 comments · Fixed by #2307
Assignees
Milestone

Comments

@behnazh-w
Copy link

behnazh-w commented Sep 25, 2023

Astroid version 2.15.7 fails to correctly handle a subscriptable type parameter most likely due to the change in this PR.

Steps to reproduce

from collections.abc import Mapping
from typing import Generic, TypeVar, TypedDict
from dataclasses import dataclass

class Identity(TypedDict):
    """It's the identity."""

    name: str

T = TypeVar("T", bound=Mapping)

@dataclass
class Animal(Generic[T]):
    """It's an animal."""

    identity: T

class Dog(Animal[Identity]):
    """It's a Dog."""

dog = Dog(identity=Identity(name="Dog"))
print(dog.identity["name"])

Current behavior

Pylint (running Astroid 2.15.7) gives the following error for the example above:

E1136: Value 'dog.identity' is unsubscriptable (unsubscriptable-object)

Expected behavior

Astroid should correctly handle a subscriptable type parameter.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.15.7

@jacobtylerwalls
Copy link
Member

Thanks for the report.

@jacobtylerwalls
Copy link
Member

@mbyrnepr2 Would you be willing to take a look?

mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Sep 25, 2023
- Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name.

Closes pylint-dev#2305
Closes pylint-dev/pylint#9069
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Sep 25, 2023
- Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name.

Closes pylint-dev#2305
Closes pylint-dev/pylint#9069
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 25, 2023
jacobtylerwalls pushed a commit that referenced this issue Sep 26, 2023
Fix a regression in 2.15.7 for ``unsubscriptable-object``.

Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name.
This reverts commit 89dfb48.

Closes #2305
Closes pylint-dev/pylint#9069
github-actions bot pushed a commit that referenced this issue Sep 26, 2023
Fix a regression in 2.15.7 for ``unsubscriptable-object``.

Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name.
This reverts commit 89dfb48.

Closes #2305
Closes pylint-dev/pylint#9069

(cherry picked from commit 1f0f2f8)
jacobtylerwalls pushed a commit that referenced this issue Sep 26, 2023
Fix a regression in 2.15.7 for ``unsubscriptable-object``.

Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name.
This reverts commit 89dfb48.

Closes #2305
Closes pylint-dev/pylint#9069

(cherry picked from commit 1f0f2f8)

Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 26, 2023
Pierre-Sassoulas pushed a commit to mbyrnepr2/pylint that referenced this issue Sep 27, 2023
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this issue Sep 30, 2023
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this issue Sep 30, 2023
Refs #9069
Refs pylint-dev/astroid#2305

(cherry picked from commit 04f7b3d)
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.

4 participants