From b2afb38655a1d32c8b04f023f3d1a10f88c36396 Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Mon, 25 Sep 2023 21:13:34 +0200 Subject: [PATCH] Add regression tests. Refs #9069 Refs pylint-dev/astroid#2305 --- tests/functional/n/no/no_member_typevar.py | 25 ++++++++++++++++ tests/functional/u/unsubscriptable_object.py | 31 ++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/functional/n/no/no_member_typevar.py diff --git a/tests/functional/n/no/no_member_typevar.py b/tests/functional/n/no/no_member_typevar.py new file mode 100644 index 00000000000..1cf59dd39ca --- /dev/null +++ b/tests/functional/n/no/no_member_typevar.py @@ -0,0 +1,25 @@ +# pylint: disable=missing-module-docstring, invalid-name, missing-class-docstring, unused-variable + + +from dataclasses import dataclass +from typing import Generic, TypeVar + + +T_Inner = TypeVar("T_Inner", bound="Inner") + + +@dataclass +class Inner: + inner_attribute: str + + +@dataclass +class Outer(Generic[T_Inner]): + inner: T_Inner + + +x = Outer(inner=Inner(inner_attribute="magic xylophone")) + +# Test `no-member` is not emitted here. +# https://github.com/pylint-dev/pylint/issues/9069 +print(x.inner.inner_attribute) diff --git a/tests/functional/u/unsubscriptable_object.py b/tests/functional/u/unsubscriptable_object.py index 4f21871d053..a98666f154e 100644 --- a/tests/functional/u/unsubscriptable_object.py +++ b/tests/functional/u/unsubscriptable_object.py @@ -1,7 +1,34 @@ """Tests for unscubscriptable-object""" -# Test for typing.NamedTuple -# See: https://github.com/pylint-dev/pylint/issues/1295 +# pylint: disable=unused-variable, too-few-public-methods + import typing +from collections.abc import Mapping +from typing import Generic, TypeVar, TypedDict +from dataclasses import dataclass + +# Test for typing.NamedTuple +# See: https://github.com/pylint-dev/pylint/issues/1295 MyType = typing.Tuple[str, str] + + +# https://github.com/pylint-dev/astroid/issues/2305 +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"])