file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
code_snippets/mypy/4000-4999/4864.py
Python
from typing import Any, Union class A: pass class B(A): def __init__(self): self.member = 1 class C(A): def __init__(self): self.member = 2 def f(obj: A) -> int: if isinstance(obj, B): pass elif isinstance(obj, C): pass else: raise ValueError() ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4886.py
Python
class Test: a: int reveal_type(Test.a + 1)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4893.py
Python
from typing import cast import numpy as np # type: ignore class C: ... a = cast(C, np.array([1,2,3])) b: C = np.array([1,2,3])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4930.py
Python
from mypackage.submod1 import * # * -> HELLO and error goes away from mypackage.submod2 import greet # comment out and error goes away __all__ = ['HELLO', 'greet'] # does nothing __all__ = ['HELLO'] HELLO = 'hello there' from mypackage import HELLO __all__ = ['greet'] def greet(): print(HELLO)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4949.py
Python
T = TypeVar('T', bound = A) def check_subtype(instance: A, instance_type: Tuple[Type[T], ...]) -> Optional[T]: if isinstance(instance, instance_type): return instance return None T = TypeVar('T', bound = A) def check_subtype(instance: A, instance_type: Type[T]) -> Optional[T]: if isinstance(instanc...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4952.py
Python
from typing import * class A(object): def method(self) -> str: return '' R = TypeVar('R') class B(object): def func(self, instance: A, instance_type: Type[R]) -> None: reveal_type(instance) if isinstance(instance, instance_type): reveal_type(instance) instance....
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4954.py
Python
from typing import Iterable, Container, Union i: Iterable[str] c: Container[str] u: Union[Iterable[str], Container[str]] 'x' in i 'x' in c 'x' in u # Unsupported right operand type for in ("Union[Iterable[str], Container[str]]")
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4973.py
Python
class A: pass class B(A): foo: str def bar(a: A): assert isinstance(a, B) return a.foo class A: pass class B(A): foo: str def bar(a: A): assert isinstance(a, B) return map(lambda _: a.foo, [])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/4000-4999/4990.py
Python
from typing import NewType class C: @classmethod def foo(cls) -> int: pass D = NewType('D', C) D.foo() # Runtime error here (line 5)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5001.py
Python
import arbitrary_module def f() -> arbitrary_module.MyType: x = 1 y = 2 # reveal_type(arbitrary_module.MyType)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5017.py
Python
O = TypeVar('O') def decorator(method : Callable[[O, VarArg(), KwArg()], Any]) -> Callable[[VarArg(), O, KwArg()], Any]: def x(*args, **kwargs): return method(args[-1], *args[0:-1], **kwargs) return x
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5018.py
Python
# file default_config.py timeout = 100 one_flag = True other_flag = False # file __main__.py import default_config from typing import Protocol class Options(Protocol): timeout: int one_flag: bool other_flag: bool def setup(options: Options) -> None: ... setup(default_config) # OK
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5028.py
Python
# a.py def add_int(a, b): return a + b add_int("a", "b") # mypy does not complain, actually ignores the entire file # a.pyi def add_int(a:int, b:int) -> int: ... # client.py from a import add_int add_int(1, 2) add_int(1, "2") # here mypy is going to complain
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5040.py
Python
import typing as typ T = typ.TypeVar('T') def identity(x:T)->T: return x A = typ.TypeVar('A') B = typ.TypeVar('B') C = typ.TypeVar('C') def compose_and_apply(x : A ,f : typ.Callable[[A],B] = identity ,g : typ.Callable[[B],C] = identity ) -> C: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5055.py
Python
from collections import defaultdict from typing import Dict, Set error_dict:Dict[str, int] = defaultdict(set) correct_dict:Dict[str, Set[int]] = defaultdict(set)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5068.py
Python
from typing import Tuple def test_1(inp1: Tuple[int, int, int]) -> None: pass def test_2(inp2: Tuple[int, int, int]) -> None: test_tuple = tuple(e for e in inp2) reveal_type(test_tuple) test_1(test_tuple)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5069.py
Python
from typing import NamedTuple class A(NamedTuple): ''' value class combining origin coordinate with list of destination coordinates ''' a: str def foo() -> None: A("david") greet = lambda a: A("hi " + a) greet('moshe')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5070.py
Python
from typing import AsyncGenerator async def gen1() -> AsyncGenerator[str, None]: pass reveal_type(gen1) async def gen2() -> AsyncGenerator[str, None]: yield 'tick' reveal_type(gen2) class BaseClass: async def gen1(self) -> AsyncGenerator[str, None]: pass reveal_type(BaseClass.gen1) class MyClass...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5080.py
Python
try: raise Exception() except Exception as e: pass e = 4 # error: Assignment to variable 'e' outside except: block
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5090.py
Python
d = {'k1': 'qwe', 'k2': []} reveal_type(d) value: str = d['k1']
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5107.py
Python
@lru_cache(maxsize=1) def get_response_from_api() -> List[ApiObject]: url = _get_api_url() response = requests.get(url).text return json.loads(response, object_hook=_create_api_obj)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5111.py
Python
if condition: s = get_str() else: s = get_optional_str() if condition: s: Optional[str] = get_str() else: s = get_optional_str() s: Optional[str] if condition: s = get_str() else: s = get_optional_str() if condition: model = get_foo_model() # FooModel else: model = get_bar_model() # BarModel # mo...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5125.py
Python
from typing import Any, Callable, Awaitable AnyFunction = Callable[..., Awaitable[Any]] def retry() -> Callable[[AnyFunction], AnyFunction]: def decorator(fn: AnyFunction) -> AnyFunction: return fn return decorator class B: async def run(self) -> bool: return True class C(B): @retry(...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5128.py
Python
def foo() -> None: message = 'test' raise Exception(message) if message else Exception # -> mypy error def bar() -> None: raise Exception # ok def baz() -> None: message = 'test' raise Exception(message) # ok def qux() -> None: message = 'test' raise Exception if not message else Ex...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5134.py
Python
from typing import Type from external import ExtBase class Base(ExtBase): pass class Concrete1(Base): pass class Concrete2(Concrete1): pass def f(x: Type[Base]) -> None: pass def g(x: bool) -> None: #reveal_type(Base) #reveal_type(Concrete1) #reveal_type(Concrete2) #reveal_typ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5144.py
Python
from typing import ClassVar, Type, Generic, TypeVar _T = TypeVar('_T') class Array(Generic[_T]): _length_: ClassVar[int] _type_: ClassVar[Type[_T]] def generate() -> Type[Array[float]]: pass generate()._type_(3)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5149.py
Python
from mypy_extensions import TypedDict Data = TypedDict("Data", {"i": {"j": int}}) def access(data: Data) -> None: data["i"]["j"] += 1 mydata = {"i": {"j": 5}} # type: Data access(mydata) Intermediate = TypedDict("Intermediate", {"j": int}) Data = TypedDict("Data", {"i": Intermediate})
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5152.py
Python
def replace(obj: _T, **changes: Any) -> _T: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5213.py
Python
class Item: def name(self) -> str: ... def f(x: Item) -> None: print('name: {}'.format(x.name)) # No error, though should be x.name() print('name: %s' % x.name) # Similar to above foo(str(x.name)) # Ditto
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5219.py
Python
class A: pass class B(A): pass class C(A): pass x = [B(), C()] # Inferrred type List[A], not List[Union[B, C]] y: List[Union[B, C]] y = [B(), C()] # Now the type is List[Union[B, C]]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5247.py
Python
x, y = zip(*a)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5272.py
Python
from pynamodb.attributes import MapAttribute, NumberAttribute from pynamodb.models import Model class MyMapAttribute(MapAttribute): foo = NumberAttribute() bar = NumberAttribute() class MyModel(Model): my_map = MyMapAttribute() class MapAttribute(...): @overload def __get__(self: _MT, instance: Mode...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5277.py
Python
T = TypeVar('T') class Fooable(Protocol): def foo(self: T, a: T) -> int: ... class A: a = 1 def foo(self, a: 'A') -> int: return self.a + a.a class B: b = 1 def foo(self, b: 'B') -> int: return self.b + b.b def foo(a: Fooable, b: Fooable) -> None: a.foo(b) foo(A(), B())
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5289.py
Python
#!/usr/bin/python2.7 from typing import Dict, Set # noqa x = {} # type: Dict[str, Set[str]] z = x[''] = set() # okay x[''] = y = set() # fail: Incompatible types in assignment (expression has type "Set[<nothing>]", target has type "Set[str]")
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5304.py
Python
from typing import Iterable, Dict, List, Sequence # error: Incompatible types in assignment (expression has type "Tuple[List[Tuple[str, str]]]", variable has type "Iterable[List[Iterable[str]]]") fields1: Sequence[List[Sequence[str]]] = ([('one', 'two')],) # error: Incompatible types in assignment (expression has typ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5310.py
Python
from typing import Optional def foo(bla: Optional[str] = None): bla_is_none = bla is None if bla_is_none: bla = "blabla" bla.lower() from typing import Optional def foo(bla: Optional[str] = None): if bla is None: bla = "blabla" bla.lower()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5311.py
Python
dct = {"": ""} # ok trans = str.maketrans(dct) "".translate(trans) # err "".translate(str.maketrans(dct))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5313.py
Python
# test.py import re import attr @attr.s class Test: foo = attr.ib(converter=re.compile) test = Test("foo")
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5324.py
Python
from typing import Generic, TypeVar class A: pass class B: pass T_Value = TypeVar("T_Value", A, B) class Guess(Generic[T_Value]): def __init__(self, value: T_Value, confidence: float) -> None: self.value = value # <-- line 17 self.confidence = confidence class Guess(Generic[T_Value...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5343.py
Python
x: str = 1 y: int = 'hello'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5359.py
Python
from mypy_extensions import TypedDict GroupDataDict = TypedDict( 'GroupDataDict', {"children": str, "vars": str, "hosts": str}, total=False ) test_group: GroupDataDict = {} key = "children" if key in ("children", "vars"): test_group[key] = "a" if key not in ["child...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5362.py
Python
from enum import Enum from typing import NamedTuple class T(NamedTuple): class State(Enum): A =1 state:State print(T.State.A) print(T(state=T.State.A))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5374.py
Python
import abc from dataclasses import dataclass @dataclass # error: Only concrete class can be given where "Type[Abstract]" is expected class Abstract(metaclass=abc.ABCMeta): a: str @abc.abstractmethod def c(self) -> None: pass @dataclass class Concrete(Abstract): b: str def c(self) -> N...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5382.py
Python
from concurrent.futures import ThreadPoolExecutor import sys opts = {'max_workers': None} if sys.version_info >= (3, 6): opts['thread_name_prefix'] = 'SyncWorker' executor = ThreadPoolExecutor(**opts)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5383.py
Python
from dataclasses import dataclass dataclass_alias = dataclass dataclass_alias2 = dataclass(order=False) def dataclass_wrapper(cls): return dataclass(cls) @dataclass class A: arg1: int @dataclass_alias class B: arg1: int @dataclass_alias2 class C: arg1: int @dataclass_wrapper class D: arg1: int a = A(arg1=1) b =...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5390.py
Python
from typing import * class MyProtocol(Protocol): def foo(self) -> int: pass class SomeClass: def foo(self) -> str: pass def test(x: Type[MyProtocol]) -> None: pass test(SomeClass) def test(x: MyProtocol) -> None: pass test(SomeClass()) T = TypeVar('T') class Wrapper(Generic[T]): def __init__(self, x: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5392.py
Python
from typing import SupportsFloat class Floaty: def __float__(self): ... class Supporter(SupportsFloat): def __float__(self): ... reveal_type(Floaty() if bool() else 0) reveal_type(Supporter() if bool() else 0)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5400.py
Python
from typing import Sequence def process_elems(elems: Sequence[float]): for elem in elems: pass assert isinstance(elem, int) elems_odd = [elem & 1 for elem in elems]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5416.py
Python
from typing import TypeVar, Generic T = TypeVar('T', int, str) class K(Generic[T]): @classmethod def m(cls) -> T: raise NotImplementedError from typing import TypeVar, Generic S = TypeVar('S') T = TypeVar('T', int, str) class K(Generic[T]): @classmethod def m(cls: S) -> T: raise NotImplementedError from typin...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5423.py
Python
foo = None for _ in range(2): if foo is not None: print(1[2]) foo = 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5425.py
Python
from typing import Any, Callable class Parent: foo = Callable[..., int] class Child(Parent): def foo(self, val: int) -> int: return val * 2
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5439.py
Python
import functools class Foo: bar = functools foo = Foo() foo.bar # error: Member "bar" is not assignable
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5445.py
Python
from PyQt5 import QtCore class DashboardB(QtCore.QObject): pass class DashboardA(QtCore.QObject): pass def f() -> DashboardA: return DashboardB()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5479.py
Python
# a.pyi def a() -> None: ... # b.pyi def not_b() -> None: ... # c.pyi def c() -> None: ... # __init__.pyi from .a import * from .b import * from .c import c
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5481.py
Python
class Descr: def __get__(self, inst: Any, owner: Any) -> int: ... class Proto(Protocol): x: int class C: x = Descr() a: Proto = C()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5483.py
Python
import enum class A(enum.Enum): """Docstring""" reveal_type(A.__doc__) # <string>:7: error: Revealed type is '__main__.A'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5485.py
Python
from dataclasses import dataclass from typing import Callable @dataclass class Repro: fn: Callable[[int], str] r = Repro(fn=repr) assert "1" == r.fn(1) class Repro: def __init__(self, fn: Callable[[int], str]) -> None: self.fn = fn
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5490.py
Python
Callable[[Arg('x', int), VarArg(str)], int]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5492.py
Python
from typing import List, Sequence, cast class A: pass class B1(A): pass class B2(A): pass # ok list1: List[A] = [A()] * 10 # ok list2: List[A] = [B1()] * 10 list2 += [B2()] * 10 # error! list3: List[A] = [B1()] * 10 + [B2()] * 10 # error! seq3: Sequence[A] = [B1()] * 10 + [B2()] * 10 # ok, but look...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5498.py
Python
from typing import Tuple, Dict, Any class MyMeta(type): def __new__(cls, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> type: return type.__new__(name, bases, dict)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5504.py
Python
class SomeDimensions(Protocol, total=False): x: float y: float z: float ct: float
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5510.py
Python
from typing import * T = TypeVar('T') @overload def f1(x: int) -> int: ... @overload def f1(x: T) -> T: ... def f1(*args, **kwargs): pass class Wrapper(Generic[T]): @overload def f2(self, x: int) -> int: ... @overload def f2(self, x: T) -> T: ... def f2(self, *args, **kwargs): pass class Dummy(G...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5519.py
Python
def foo(a: str): pass d = {'key': 'a'} foo(d.get('key', None) or '26')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5523.py
Python
class PersonWrapper: def __init__(self, person: Person, default: Any = '') -> None: self.person = person self.default = default def __getattr__(self, attribute: str) -> Any: return getattr(self.person, attribute, self.default) def print_person(original_person: Person) -> None: pers...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5528.py
Python
from typing import Optional, List def f1(a: Optional[int], b: int)->int: assert a is not None b = a return b def f2(a: List[Optional[int]], i: int, b: int)->int: assert a[i] is not None b = a[i] return b def f3(a: List[Optional[int]], i: int, b: int)->int: ai = a[i] assert ai is not N...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5530.py
Python
def foo(key: str) -> str: return key class A: @staticmethod def foobar(key: str) -> str: return "hello world" class B(A): foobar = staticmethod(foo)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5540.py
Python
from typing import Optional def f(x:Optional[str]) -> bool: return bool(x) and g(x) def f2(x:Optional[str]) -> bool: if x: return g(x) return False def g(x: str) -> bool: return bool(x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5541.py
Python
from clize import run from clize.parameters import argument_decorator @argument_decorator def capitalize(arg, *, capitalize:('c', 'upper')=False, reverse:'r'=False): """ Options to qualify {param}: :param capitalize: Make {param} uppercased :param reverse: Reverse {param} """ if capitalize: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5550.py
Python
def ensure_native_str(str_or_bytes): # type: (Union[Text, bytes]) -> str return ( str_or_bytes if isinstance(str_or_bytes, str) else str_or_bytes.decode('utf-8') if six.PY3 else str_or_bytes.encode('utf-8') ) def ensure_native_str(str_or_bytes): # type: (Union[Text, bytes]) -> str ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5551.py
Python
from typing import TypeVar, Generic class C(Generic[T]): def __init__(self, t: T) -> None: self.t = t class F(Generic[K]): def __init__(self, k: K) -> None: self.k = k def foo(self) -> K: return self.k C.F(17).foo() C("").F(17).foo() # error: Argument 1 to "F...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5570.py
Python
from typing import Any, Union class getter: def __get__(self, instance: "X1", owner: Any) -> str: return "" class X1: prop = getter() class X2: def __init__(self) -> None: self.prop = "" def foo(x: Union[X1, X2]) -> None: x.prop
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5579.py
Python
from typing import List, Tuple, Union Nested = Union[ List[str], List[List[str]] ] FlatWithCoordinates = Union[ List[Tuple[str, int]], List[Tuple[str, int, int]], ] def f(a: Nested) -> FlatWithCoordinates: if not isinstance(a[0], List): return [ (s, x) for x, s ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5587.py
Python
from typing import ClassVar class C: x: ClassVar = 1 reveal_type(C.x) # Revealed type is 'Any'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5593.py
Python
from typing import Any, Type, TypeVar from mypy_extensions import TypedDict _T = TypeVar('_T') class C(TypedDict): x: str class D: x: str def gen_row() -> Any: return {'x': 1} def foo(cls: Type[_T]) -> _T: return gen_row() def print_c(c: C): print(c) def print_d(d: D): print(d) print_c(foo(C)) print...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5597.py
Python
s = "hello" s.replace("e", "a") assert s == "hallo"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5605.py
Python
A = TypeVar("A") f: Optional[Callable[[str], A]] = None f = lambda x: str(x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5608.py
Python
@dataclass class C: x: int y: Final[int]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5609.py
Python
import attr from typing import Union @attr.s class A: left: 'B' = attr.ib() right: 'B' = attr.ib() B = Union[list, str] def foo() -> A: # return A(left=5, right=[]) return A(left=[], right=5)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5613.py
Python
from typing import ClassVar, List, NamedTuple class Employee(NamedTuple): """Represents an employee.""" some_list_classvar: ClassVar[List] = [] # <- Doesn't work name: str id: int = 3
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5653.py
Python
class User(TypedDict): id: str firstName: str lastName: str password: str # error:Invalid statement in TypedDict definition; expected "field_name: field_type" @classmethod def from_row(cls, row: RowProxy) -> typing.Optional["User"]: if not row: return None return...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5666.py
Python
from abc import ABC, abstractmethod from typing import Generic, TypeVar _InputType = TypeVar('_InputType', contravariant=True) _IntermediateType = TypeVar('_IntermediateType') _OutputType = TypeVar('_OutputType', covariant=True) class GenericBase(Generic[_InputType, _IntermediateType, _OutputType], ABC): @abstra...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5678.py
Python
import sys from typing import Generator def f() -> Generator[int, None, None]: if sys.platform == "darwin": yield 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5687.py
Python
from abc import ABC, abstractmethod from typing import Generic, TypeVar, cast _InputType = TypeVar('_InputType', contravariant=True) _IntermediateType = TypeVar('_IntermediateType') _OutputType = TypeVar('_OutputType', covariant=True) class GenericBase(Generic[_InputType, _IntermediateType, _OutputType], ABC): @...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5703.py
Python
from typing import Generic, TypeVar, List T = TypeVar('T') class B(Generic[T]): x: List[T] = [] class C1(B[int]): pass class C2(B[str]): pass C1().x.append(42) C2().x.append('Hm...')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5720.py
Python
from typing import Generic, TypeVar T = TypeVar('T') class C(Generic[T]): def foo(self, x: T) -> None: if isinstance(x, int): self.bar(x) def bar(self, x: T) -> None: pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5723.py
Python
from dataclasses import dataclass, field from mypy_extensions import TypedDict class Person(TypedDict, total=False): name: str @dataclass class Job: person: Person = field(default_factory=Person)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5732.py
Python
def foo() -> None: global myglobal myglobal = 2 # error: Name 'myglobal' is not defined
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5736.py
Python
from foo import bar as _bar
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5738.py
Python
from typing import TypeVar, Callable, Tuple T = TypeVar('T') def f(x: Callable[..., T]) -> T: return x() x: Tuple[str, ...] = f(tuple)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5750.py
Python
#! /usr/bin/env python from typing import Dict, List, Union def main(arg): # type: (bool) -> Union[Dict[str, str], List[str]] if arg: var = list() var.append('something') else: var = dict() var['key'] = 'something' return var if __name__ == '__main__': main(True)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5752.py
Python
from typing import Type, Union from typing_extensions import Protocol class HasFoo(Protocol): # foo: str # works foo: Union[str, int] # fails def dec(cls: Type[HasFoo]) -> Type[HasFoo]: return cls @dec class Thing: foo = 'abc'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5756.py
Python
from typing import List, Optional from mypy_extensions import safe_cast def f(x: List[Optional[int]], n: int) -> List[Optional[int]]: # Mypy doesn't allow + for List[None] and List[Optional[int]], so we need a cast return safe_cast(List[Optional[int]], [None]) * n + x x: Union[int, str] = 0 reveal_type(x) # ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5774.py
Python
class C: def __new__(cls, x: int) -> C: self = object.__new__(cls) self.x: Final = x return self class C: x: Final[int] def __new__(cls) -> C: self = object.__new__(cls) self.x: Final = 1 return self
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5775.py
Python
from typing import AnyStr from typing_extensions import Protocol class PathLike(Protocol[AnyStr]): def __fspath__(self) -> AnyStr: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5795.py
Python
from typing import Optional, List, cast things: Optional[List[int]] = None others: List[int] = [] if things is not None: filtered = filter(lambda x: x in cast(List[int], things), others)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5803.py
Python
from abc import ABC, abstractmethod from typing import Any class DataProperty: def __get__(self, instance: Any, owner: Any) -> str: return "X" class BadBase1(ABC): @property @abstractmethod def id(self) -> str: raise NotImplementedError() class BadBase2(ABC): id: str class Go...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5843.py
Python
from typing import Callable, Generic, TypeVar _T = TypeVar('_T') _U = TypeVar('_U') class A(Generic[_T]): _value: _T def __init__(self, val: _T) -> None: ... def __rshift__(self, f: Callable[[_T], _U]) -> _U: ... def inc(x: int) -> int: ... A(1) >> inc # No error A(1).__rshift__(lambda x: x + 1) # No ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5849.py
Python
from typing import Union, Dict class A(object): def __init__(self, user: Dict[str, Union[str, bool, list, Dict[str, Union[bool, list]]]]): d1 = { 'a': user['name'], } d2 = { 'c': 3, } self.d3 = {**d1, **d2} print(A({'name': 'victor'}).d3)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5858.py
Python
#! /usr/bin/env python import time from functools import lru_cache class MyClass: @property @lru_cache(1) def expensive_operation(self) -> int: time.sleep(2) return 42 def another_operation(self) -> int: return self.expensive_operation + 1 if __name__ == '__main__': o = MyClass() print(o.expensive_opera...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5865.py
Python
from typing import Any a: Any class C(a): pass # Ok def f(b: Any) -> None: class D(b): pass # Errors: Invalid type "b"; Invalid base class def g(c: Any) -> None: d: Any = c class E(d): pass # Ok
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli