File: typing.py

package info (click to toggle)
freeipa 4.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 367,240 kB
  • sloc: javascript: 562,763; python: 310,289; ansic: 49,809; sh: 7,176; makefile: 2,589; xml: 343; sed: 16
file content (33 lines) | stat: -rw-r--r-- 769 bytes parent folder | download | duplicates (3)
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
#
# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
#

import weakref


_cache = weakref.WeakValueDictionary()


class ListMeta(type):
    def __getitem__(cls, key):
        if not isinstance(key, type):
            raise TypeError("Parameters to generic types must be types. "
                            "Got {!r}.".format(key))

        t = ListMeta(
            cls.__name__,
            cls.__bases__,
            {
                '__parameters__': (key,),
                '__init__': cls.__init__,
            }
        )

        return _cache.get(key, t)


class List(list, metaclass=ListMeta):
    __parameters__ = ()

    def __init__(self, *_args, **_kwargs):
        raise TypeError("Type List cannot be instantiated; use list() instead")