summaryrefslogtreecommitdiff
path: root/tests/functional/g/generic_alias/generic_alias_related_py39.py
blob: 14445a043fe717f77e75fe76428813b2fa06c4ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Test related function for generic alias.

Any solution should not change the behavior of
- `__getitem__`
- `__class_getitem__`
- `metaclass=ABCMeta`
"""
# flake8: noqa
# pylint: disable=missing-docstring,pointless-statement,expression-not-assigned
# pylint: disable=too-few-public-methods,multiple-statements,line-too-long
from abc import ABCMeta, abstractmethod
import typing

GenericAlias = type(list[int])


class ClsUnsubscriptable:
    def __init__(self):
        pass

class ClsGetItem:
    def __init__(self):
        self.var = [1, 2, 3, 4]
    def __getitem__(self, item):
        return self.var[item]

class ClsClassGetItem:
    def __init__(self):
        pass
    __class_getitem__ = classmethod(GenericAlias)

class ClsList(typing.List):
    pass


ClsUnsubscriptable()[1]  # [unsubscriptable-object]
ClsUnsubscriptable[int]  # [unsubscriptable-object]

ClsGetItem()[1]
ClsGetItem[int]  # [unsubscriptable-object]

ClsClassGetItem()[1]  # [unsubscriptable-object]
ClsClassGetItem[int]

# subscriptable because of inheritance
ClsList([0, 1, 2])[1]
ClsList[int]


class ClsAbstract(metaclass=ABCMeta):
    @abstractmethod
    def abstract_method(self):
        pass

class Derived(ClsAbstract):  # [abstract-method]
    pass