• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python typing.typevar函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中typing.typevar函数的典型用法代码示例。如果您正苦于以下问题:Python typevar函数的具体用法?Python typevar怎么用?Python typevar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了typevar函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_generic_class_with_two_typeargs

    def test_generic_class_with_two_typeargs(self):
        t = typevar('t')
        u = typevar('u')

        class C(Generic[t, u]):
            pass

        self.assertIs(C[int, str], C)
        self.assertIsInstance(C(), C)
        self.assertIsInstance(C[int, str](), C)
开发者ID:kivipe,项目名称:mypy,代码行数:10,代码来源:test_typing.py


示例2: test_generic_protocol

 def test_generic_protocol(self):
     t = typevar('t')
     class P(Protocol[t]):
         x = 1
     class A:
         x = 2
     self.assertIsInstance(A(), P)
开发者ID:kivipe,项目名称:mypy,代码行数:7,代码来源:test_typing.py


示例3: test_simple_generic_class

    def test_simple_generic_class(self):
        t = typevar('t')

        class C(Generic[t]):
            pass

        self.assertIs(C[int], C)
        self.assertIsInstance(C(), C)
        self.assertIsInstance(C[int](), C)
开发者ID:kivipe,项目名称:mypy,代码行数:9,代码来源:test_typing.py


示例4: test_abstract_generic_class

 def test_abstract_generic_class(self):
     t = typevar('t')
     class C(AbstractGeneric[t]):
         pass
     class D:
         pass
     self.assertIs(C[int], C)
     self.assertNotIsInstance(D(), C)
     C.register(D)
     self.assertIsInstance(D(), C)
开发者ID:kivipe,项目名称:mypy,代码行数:10,代码来源:test_typing.py


示例5: test_typevar_in_overload

    def test_typevar_in_overload(self):
        t = typevar('t')

        @overload
        def f(x:t, y:str): return 1
        @overload
        def f(x, y): return 2

        self.assertEqual(f((), 'x'), 1)
        self.assertEqual(f((), 1.1), 2)
开发者ID:kivipe,项目名称:mypy,代码行数:10,代码来源:test_typing.py


示例6: test_construct_class_with_abstract_method

    def test_construct_class_with_abstract_method(self):
        t = typevar('t')

        class A(AbstractGeneric[t]):
            @abstractmethod
            def f(self): pass

        class B(A):
            def f(self): pass

        with self.assertRaises(TypeError):
            A()
        B()
开发者ID:kivipe,项目名称:mypy,代码行数:13,代码来源:test_typing.py


示例7: typevar

#!/usr/bin/env python3

import unittest
import random
import time
import pickle
import warnings
from math import log, exp, pi, fsum, sin
from test import support

from typing import Undefined, Any, Dict, List, Function, Generic, typevar

RT = typevar('RT', values=(random.Random, random.SystemRandom))

class TestBasicOps(unittest.TestCase, Generic[RT]):
    # Superclass with tests common to all generators.
    # Subclasses must arrange for self.gen to retrieve the Random instance
    # to be tested.

    gen = Undefined(RT) # Either Random or SystemRandom 

    def randomlist(self, n: int) -> List[float]:
        """Helper function to make a list of random numbers"""
        return [self.gen.random() for i in range(n)]

    def test_autoseed(self) -> None:
        self.gen.seed()
        state1 = self.gen.getstate()
        time.sleep(0.1)
        self.gen.seed()      # diffent seeds at different times
        state2 = self.gen.getstate()
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:31,代码来源:test_random.py


示例8: typevar

from typing import typevar, Any

_FT = typevar("_FT")


def register(func: _FT, *args: Any, **kargs: Any) -> _FT:
    pass
开发者ID:akaihola,项目名称:mypy,代码行数:7,代码来源:atexit.py


示例9: typevar

"""Generic abstract syntax tree node visitor"""

from typing import typevar, Generic

import mypy.nodes


T = typevar('T')


class NodeVisitor(Generic[T]):
    """Empty base class for parse tree node visitors.

    The T type argument specifies the return type of the visit
    methods. As all methods defined here return None by default,
    subclasses do not always need to override all the methods.

    TODO make the default return value explicit
    """
    
    # Module structure
    
    def visit_mypy_file(self, o: 'mypy.nodes.MypyFile') -> T:
        pass
    
    def visit_import(self, o: 'mypy.nodes.Import') -> T:
        pass
    def visit_import_from(self, o: 'mypy.nodes.ImportFrom') -> T:
        pass
    def visit_import_all(self, o: 'mypy.nodes.ImportAll') -> T:
        pass
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:31,代码来源:visitor.py


示例10: import

# Stubs for builtins

from typing import (
    Undefined, typevar, AbstractGeneric, Iterator, Iterable, overload,
    Sequence, Mapping, Tuple, List, Any, Dict, Function, Generic, Set,
    AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
    SupportsRound, IO, builtinclass, ducktype, Union
)
from abc import abstractmethod, ABCMeta

# Note that names imported above are not automatically made visible via the
# implicit builtins import.

_T = typevar('_T')
_KT = typevar('_KT')
_VT = typevar('_VT')
_S = typevar('_S')
_T1 = typevar('_T1')
_T2 = typevar('_T2')
_T3 = typevar('_T3')
_T4 = typevar('_T4')

staticmethod = object() # Only valid as a decorator.
classmethod = object() # Only valid as a decorator.
property = object()

_byte_types = Union[bytes, bytearray]

@builtinclass
class object:
    __doc__ = ''
开发者ID:kivipe,项目名称:mypy,代码行数:31,代码来源:builtins.py


示例11: typevar

# Builtins stub used in dictionary-related test cases.

from typing import typevar, Generic, Iterable, Iterator

T = typevar('T')
S = typevar('S')

class object:
    def __init__(self) -> None: pass

class type: pass

class dict(Generic[T, S]): pass
class int: pass # for convenience
class str: pass # for keyword argument key type
class list(Iterable[T], Generic[T]): # needed by some test cases
    def __iter__(self) -> Iterator[T]: pass
    def __mul__(self, x: int) -> list[T]: pass
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:18,代码来源:dict.py


示例12: import

# Stubs for weakref

# NOTE: These are incomplete!

from typing import (
    typevar, Generic, Any, Function, overload, Mapping, Iterator, Dict, Tuple,
    Iterable
)

_T = typevar('_T')
_KT = typevar('_KT')
_VT = typevar('_VT')

class ReferenceType(Generic[_T]):
    # TODO members
    pass

def ref(o: _T, callback: Function[[ReferenceType[_T]],
                                 Any] = None) -> ReferenceType[_T]: pass

# TODO callback
def proxy(object: _T) -> _T: pass

class WeakValueDictionary(Generic[_KT, _VT]):
    # TODO tuple iterable argument?
    @overload
    def __init__(self) -> None: pass
    @overload
    def __init__(self, map: Mapping[_KT, _VT]) -> None: pass

    def __len__(self) -> int: pass
开发者ID:akaihola,项目名称:mypy,代码行数:31,代码来源:weakref.py


示例13: test_typevar

 def test_typevar(self):
     t = typevar(u't')
     self.assertEqual(t.name, u't')
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:3,代码来源:test_typing.py


示例14: import

"""Stubs for builtins"""

from typing import (
    Undefined, typevar, AbstractGeneric, Iterator, Iterable, overload,
    Sequence, Mapping, Tuple, List, Any, Dict, Function, Generic, Set,
    AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
    SupportsRound, TextIO
)
from abc import abstractmethod, ABCMeta

T = typevar('T')
KT = typevar('KT')
VT = typevar('VT')
S = typevar('S')
T1 = typevar('T1')
T2 = typevar('T2')
T3 = typevar('T3')
T4 = typevar('T4')


staticmethod = object() # Only valid as a decorator.
property = object()


class object:
    __doc__ = ''
    __class__ = Undefined # type: type
    
    def __init__(self) -> None: pass
    
    def __eq__(self, o: object) -> bool: pass
开发者ID:silky,项目名称:mypy,代码行数:31,代码来源:builtins.py


示例15: cases

# These builtins stubs are used implicitly in parse-tree to icode generation
# test cases (testicodegen.py and test/data/icode-basic.test).

from typing import typevar, Generic

t = typevar('t')

class object:
    def __init__(self) -> None: pass

class type: pass
class str: pass

# Primitive types are special in generated code.

class int:
    def __add__(self, n: int) -> int: pass
    def __sub__(self, n: int) -> int: pass
    def __mul__(self, n: int) -> int: pass
    def __neg__(self) -> int: pass
    def __eq__(self, n: int) -> bool: pass
    def __ne__(self, n: int) -> bool: pass
    def __lt__(self, n: int) -> bool: pass
    def __gt__(self, n: int) -> bool: pass
    def __le__(self, n: int) -> bool: pass
    def __ge__(self, n: int) -> bool: pass

class float: pass
class bool: pass

class list(Generic[t]): pass
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:31,代码来源:icodegen.py


示例16: import

# Stubs for unittest

# Based on http://docs.python.org/3.0/library/unittest.html

# NOTE: These stubs are based on the 3.0 version API, since later versions
#       would require featurs not supported currently by mypy.

# Only a subset of functionality is included.

from typing import (
    Any, Function, Iterable, Undefined, Tuple, List, TextIO, Sequence,
    overload, typevar, Pattern
)
from abc import abstractmethod, ABCMeta

T = typevar('T')
FT = typevar('FT')

class Testable(metaclass=ABCMeta):
    @abstractmethod
    def run(self, result: 'TestResult') -> None: pass
    @abstractmethod
    def debug(self) -> None: pass
    @abstractmethod
    def countTestCases(self) -> int: pass

# TODO ABC for test runners?

class TestResult:
    errors = Undefined(List[Tuple[Testable, str]])
    failures = Undefined(List[Tuple[Testable, str]])
开发者ID:zyga,项目名称:mypy,代码行数:31,代码来源:unittest.py


示例17: import

# Stubs for unittest

# Based on http://docs.python.org/3.0/library/unittest.html

# NOTE: These stubs are based on the 3.0 version API, since later versions
#       would require featurs not supported currently by mypy.

# Only a subset of functionality is included.

from typing import (
    Any, Function, Iterable, Undefined, Tuple, List, TextIO, Sequence,
    overload, typevar, Pattern
)
from abc import abstractmethod, ABCMeta

_T = typevar('_T')
_FT = typevar('_FT')

class Testable(metaclass=ABCMeta):
    @abstractmethod
    def run(self, result: 'TestResult') -> None: pass
    @abstractmethod
    def debug(self) -> None: pass
    @abstractmethod
    def countTestCases(self) -> int: pass

# TODO ABC for test runners?

class TestResult:
    errors = Undefined(List[Tuple[Testable, str]])
    failures = Undefined(List[Tuple[Testable, str]])
开发者ID:akaihola,项目名称:mypy,代码行数:31,代码来源:unittest.py


示例18: namedtuple

# Stubs for collections

# Based on http://docs.python.org/3.2/library/collections.html

# TODO namedtuple (requires language changes)
# TODO UserDict
# TODO UserList
# TODO UserString
# TODO more abstract base classes (interfaces in mypy)

from typing import (
    typevar, Iterable, AbstractGeneric, Iterator, Dict, Generic, overload,
    Mapping, List, Tuple, Undefined, Function, Set, Sequence, Sized
)

T = typevar('T')
KT = typevar('KT')
VT = typevar('VT')


class deque(Sized, Iterable[T], AbstractGeneric[T]):
    # TODO int with None default
    maxlen = 0 # TODO readonly
    def __init__(self, iterable: Iterable[T] = None,
                 maxlen: int = None) -> None: pass
    def append(self, x: T) -> None: pass
    def appendleft(self, x: T) -> None: pass
    def clear(self) -> None: pass
    def count(self, x: T) -> int: pass
    def extend(self, iterable: Iterable[T]) -> None: pass
    def extendleft(self, iterable: Iterable[T]) -> None: pass
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:31,代码来源:collections.py


示例19: import

# Stubs for unittest

# Based on http://docs.python.org/3.0/library/unittest.html

# NOTE: These stubs are based on the 3.0 version API, since later versions
#       would require featurs not supported currently by mypy.

# Only a subset of functionality is included.

from typing import (
    Any, Function, Iterable, Undefined, Tuple, List, TextIO, typevar
)
from abc import abstractmethod, ABCMeta

FT = typevar('FT')

class Testable(metaclass=ABCMeta):
    @abstractmethod
    def run(self, result: 'TestResult') -> None: pass
    @abstractmethod
    def debug(self) -> None: pass
    @abstractmethod
    def countTestCases(self) -> int: pass

# TODO ABC for test runners?

class TestResult:
    errors = Undefined(List[Tuple[Testable, str]])
    failures = Undefined(List[Tuple[Testable, str]])
    testsRun = 0
    shouldStop = False
开发者ID:silky,项目名称:mypy,代码行数:31,代码来源:unittest.py


示例20: builtins

# Stubs for builtins (Python 2.7)

from typing import (
    Undefined, typevar, AbstractGeneric, Iterator, Iterable, overload,
    Sequence, Mapping, Tuple, List, Any, Dict, Function, Generic, Set,
    AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
    SupportsRound, IO, BinaryIO, builtinclass, ducktype, Union, AnyStr
)
from abc import abstractmethod, ABCMeta

_T = typevar('_T')
_KT = typevar('_KT')
_VT = typevar('_VT')
_S = typevar('_S')
_T1 = typevar('_T1')
_T2 = typevar('_T2')
_T3 = typevar('_T3')
_T4 = typevar('_T4')

staticmethod = object() # Only valid as a decorator.
classmethod = object() # Only valid as a decorator.
property = object()

@builtinclass
class object:
    __doc__ = ''
    __class__ = Undefined # type: type

    def __init__(self) -> None: pass
    def __eq__(self, o: object) -> bool: pass
    def __ne__(self, o: object) -> bool: pass
开发者ID:kivipe,项目名称:mypy,代码行数:31,代码来源:builtins.py



注:本文中的typing.typevar函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python typing.BinaryIO类代码示例发布时间:2022-05-27
下一篇:
Python typing.type_check_bmch函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap