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/5000-5999/5874.py
Python
T = TypeVar('T') S = TypeVar('S') def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ... a: List[int] b: List[str] e: List[Union[int, str]] = add(a, b)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5876.py
Python
from typing import Any class A: # A method that accepts unspecified arguments and returns int def f(self, *args: Any, **kwargs: Any) -> int: pass class B(A): def f(self, x: int) -> int: pass # Should be okay from typing import Any, Callable, TypeVar T = TypeVar('T', bound=Callable[..., Any]) def deco(...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5879.py
Python
from typing import Callable, Tuple, TypeVar, overload T = TypeVar('T') A0 = TypeVar('A0') A1 = TypeVar('A1') @overload def foo( vars: Tuple[A0], op: Callable[[A0], T] ) -> T: ... @overload def foo( vars: Tuple[A0, A1], op: Callable[[A0, A1], T] ) -> T: ... def foo(vars, op): pass def foo_no...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5897.py
Python
from typing import Type, TypeVar, TYPE_CHECKING class A: def __init__(self, arg: int) -> None: self._arg = arg class B(A): def __init__(self, arg: int) -> None: super().__init__(arg) _TA = TypeVar('_TA', bound=A) def get_entity(entity_class: Type[_TA], arg: int) -> _TA: if TYPE_CHECK...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5911.py
Python
INSTALLED_APPS = ('app1', 'app2') from django.db import models class User(models.Model): member = models.ForeignKey(to='app1.Model1')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5928.py
Python
# foo.py from typing import Tuple, Type class A: pass class B: pass PlainBases = (A, B) reveal_type(PlainBases) # ^ Revealed type is 'Tuple[def () -> foo.A, def () -> foo.B]' class PlainC(*PlainBases): # ^ Invalid base class pass AnotatedBases = (A, B) # type: Tuple[Type[A], Type[B]] reveal_type(AnotatedBases)...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5936.py
Python
class Base: def __init__(self, value): self._value = value @property def value(self): return self._value class Sub(Base): @Base.value.setter def value(self, value): self._value = value class Base: def __init__(self, value): self._value = value @property def value(self): return self._value @value...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5940.py
Python
import sys if sys.version_info < (3,): class X: def foo(self) -> int: ... class Y(X): def foo(self) -> str: ... # type: ignore
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5941.py
Python
class Foo: __slots__ = ['a'] instance = Foo() instance.a = 10 # <-- False positive ("Foo" has no attribute "a") instance.b = 20 # <-- True positive class Bar: __slots__ = {'a': int} instance2 = Bar() instance2.a = 10 instance2.a = 'foo' # <-- I would expect an error here
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5964.py
Python
# flags: --always-false=IS_WINDOWS if IS_WINDOWS: import win_specific_import def some_fun_broken() -> int: if not IS_WINDOWS: return 1 # checked # The rest of this function is analyzed even though we returned above. # Blows up since `win_specific_import` isn't defined return win_specific_...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5968.py
Python
from typing import Any from non_existent import f # type: ignore # Not in the build def g(): pass def h() -> None: g(asdf=1) # Error: Call to untyped function "g" in typed context f(asdf=1) # No error reported, but this is untyped ff: Any ff() # No error reported, and again this in untyped
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5971.py
Python
from typing import TypeVar, Generic, Union, Any T = TypeVar('T') Tcov = TypeVar('Tcov', covariant=True) S = TypeVar('S') class A(Generic[Tcov]): pass class B(A[T]): def __add__(self, x: B[S]) -> B[Union[T, S]]: ... a: A[object] b1: B[Any] b2: B[int] a = b1 + b2 # Unsupported operand types for + ("B[Any]" and ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5980.py
Python
# pair.py from typing import Tuple, TypeVar A = TypeVar('A') B = TypeVar('B') Pair = Tuple[A, B] def fst(pair: Pair[A, B]) -> A: a, _ = pair return a def snd(pair: Pair[A, B]) -> B: _, b = pair return b # test.py import pair from pair import Pair def f(p: Pair[int, float]) -> float: return pai...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/5000-5999/5986.py
Python
import handler.pics
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6037.py
Python
from enum import Enum class Foo(Enum): "" Bar: type = Enum('Bar', ['X', 'Y']) # line 6 Baz: type = Foo('Baz', ['X', 'Y']) # line 7 bar: Bar = Bar.X # line 9 baz: Baz = Baz.Y # line 10
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6040.py
Python
from typing import Iterable, TYPE_CHECKING, TypeVar _TC = TypeVar('_TC', int, float, complex) def f1(arg: Iterable[complex]) -> complex: if TYPE_CHECKING: reveal_type(f2(arg)) # Revealed type is 'builtins.complex' Ok. reveal_type(1/f2(arg)) # Revealed type is 'builtin...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6060.py
Python
from typing import Union def maybe_convert_to_int(x: Union[float,int]) -> Union[float,int]: '''Convert x from float to int if it can be done losslessly.''' if isinstance(x, float): # x must be a float here, so this is a legal operation, but # mypy still thinks its type is Union[float,int] ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6063.py
Python
from typing import NamedTuple from dataclasses import make_dataclass, dataclass Emp1 = NamedTuple('Emp1', [('name', str), ('id', int)]) r1 = Emp1('raymond', 'xyz') Emp2 = make_dataclass('Emp2', [('name', str), ('id', int)]) r2 = Emp2('raymond', 'xyz') class Emp3(NamedTuple): name: str id: int r3 = Emp3('ray...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6066.py
Python
from typing import TypeVar, Generic, List ContainedType = TypeVar('ContainedType', bound='ContainedCls') SubContained = TypeVar('SubContained') T = TypeVar('T') class Root_wrong(Generic[ContainedType[SubContained]]): def __init__(self, ct): # type: (ContainedType[SubContained]) -> None self.contai...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6079.py
Python
d = {"1": 2, 3: 4} reveal_type(d) # builtins.dict[builtins.object*, builtins.int*]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6089.py
Python
from __future__ import annotations from typing import Optional class C1(object): def foo(self, a: C, b: C) -> None: reveal_type(a) # Optional[C1] reveal_type(b) # Any def bar(self, a: C) -> C: reveal_type(a) # Optional[C1] return a def baz(self) -> C: return C()...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6101.py
Python
# NoReturn was introduced in Python 3.6.5. if TYPE_CHECKING: from typing_extensions import NoReturn else: NoReturn = None
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6104.py
Python
from typing import TYPE_CHECKING if TYPE_CHECKING: from typing import NamedTuple class C(NamedTuple): x: int y: int
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6131.py
Python
EnvironDict = TypedDict("EnvironDict", { "wsgi.version": Tuple[int, int], "wsgi.input": IO[str], # ... }, default_type=str, total=False)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6132.py
Python
import typing T = typing.TypeVar('T') def same(obj: T) -> T: return obj add = same(3).__add__ TypeVar = same(typing).TypeVar
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6135.py
Python
import enum import operator OperatorEnum = enum.Enum( "OperatorEnum", {"==": operator.eq, ">=": operator.ge, "<=": operator.le, ">": operator.gt, "<": operator.lt}, ) OperatorEnum["foo"] # pass, but should throw an error? OperatorEnum.foo # Fails
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6136.py
Python
@attr.s(auto_attribs=True) class Foo: bars: List[Bar] = attr.ib( default=attr.Factory(list), converter=default_if_none(default=attr.Factory(list)), )
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6140.py
Python
@overload def deco(f: Callable[[], int]) -> Callable[[], str]: ... @overload def deco(f: Callable[..., int]) -> Callable[..., str]: ... def deco(f): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6143.py
Python
import attr # example 1 (works with mypy) @attr.s(auto_attribs=True, frozen=True) class DirectlyDecorated: name: str d = DirectlyDecorated('foo') # no mypy error # --- end example 1 # example 2 (does not work with mypy) my_decorator = attr.s(auto_attribs=True, frozen=True) @my_decorator class IndirectlyD...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6158.py
Python
class CustomProperty(property): def __init__(self, fget=None, fset=None, fdel=None, doc=None): super().__init__(fget, fset, fdel, doc) class A: def __init__(self) -> None: self._val = 1 @CustomProperty def val(self) -> int: return self._val @val.setter def val(self, v:...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6164.py
Python
from typing import Callable, Tuple, TypeVar, Iterator, Any, overload T1 = TypeVar("T1") T2 = TypeVar("T2") S = TypeVar("S") @overload def star(f: Callable[[T1], S]) -> Callable[[Tuple[T1]], S]: ... @overload def star(f: Callable[[T1, T2], S]) -> Callable[[Tuple[T1, T2]], S]: ... def star(f: Any) -> Any: def wra...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6168.py
Python
from typing import Union class A: x: Union[int, float] def foo(x: Union[int, float], y: A) -> None: reveal_type(x) reveal_type(y.x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6172.py
Python
import attr def foo(value): return value.split() @attr.s class Bar: field = attr.ib(default=None, converter=foo)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6178.py
Python
from typing import Generic, TypeVar T_co = TypeVar("T_co", covariant=True) class C(Generic[T_co]): def __init__(self, x: T_co) -> None: ... @classmethod def custom_init(cls, x: T_co) -> "C[T_co]": # error: Cannot use a covariant type variable as a parameter return cls(x) T_cov =...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6184.py
Python
from abc import ABCMeta, abstractmethod from typing import Generic, TypeVar, Union A = TypeVar('A') class Base(Generic[A]): __metaclass__ = ABCMeta @abstractmethod def do_stuff(self, a): # type: (A) -> None pass class Foo(Generic[A], Base[A]): pass class Bar(Generic[A], Base[A]):...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6185.py
Python
class A(): @property def a(self) -> float: return 0.5 class B(): @property def a(self) -> float: return 1.5 class C(A, B): is_a:bool = True @property def a(self) -> float: if self.is_a: return A.a.fget(self) else: return B.a.fget(sel...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6189.py
Python
# t.py import sys as py_sys if py_sys.version_info < (3, 0): unicode = unicode chr = unichr else: unicode = str # t.py import sys if sys.version_info < (3, 0): unicode = unicode chr = unichr else: unicode = str
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6192.py
Python
from typing import NamedTuple class C(NamedTuple): a: int = 1 print(C.a * 2)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6200.py
Python
from typing import NamedTuple, TypeVar, Generic from typing_extensions import Protocol from mypy_extensions import TypedDict @xyz # No error class N1(NamedTuple): x: int @xyz # No error class T1(TypedDict): x: int class N2(NamedTuple, Protocol): # No error x: int class T2(TypedDict, Protocol): # No er...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6212.py
Python
import ctypes Quaternion = ctypes.c_int * 4 Pair = Quaternion * 2 quat = Quaternion(1, 2, 3, 4) p = Pair((1, 2, 3, 4), (2, 3, 4, 5))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6216.py
Python
import sys class A: def f(self) -> None: if sys.platform == 'xxx': import bad # Error def g() -> None: if sys.platform == 'xxx': import bad2 # No error
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6217.py
Python
from dataclasses import dataclass @dataclass class Foo: bar: str @classmethod def bar(cls) -> "Foo": return cls()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6220.py
Python
from typing import Callable, TypeVar, Any, List T = TypeVar('T') T1 = TypeVar('T1') T2 = TypeVar('T2') def chain(f1: Callable[[Any],T1], f2: Callable[[T1], T2]) -> Callable[[Any], T2]: def chained(x: Any) -> T2: return f2(f1(x)) return chained # Two toy functions def identity(x: T) -> T: retu...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6224.py
Python
NT = TypeVar('NT', int, float) NTU = Union['KspVar[NT]', 'AstBase[NT]', 'ProcessNum[NT]', NT] class AstOperatorUnary(AstBase[NT], ProcessNum[NT]): arg1: NTU[NT] string: ClassVar[str] priority: ClassVar[int] def __init__(self, arg1: NTU[NT]) -> None: self.arg1: NTU[NT] = arg1 self.arg1...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6225.py
Python
class A: def __add__(self, other) -> int: ... def __iadd__(self, other) -> 'A': ... class C(A): # error: Return type of "__iadd__" incompatible with "__add__" of supertype "A" def __iadd__(self, other) -> 'C': ... __add__ __iadd__
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6227.py
Python
from typing import Iterable, Union def as_bytes(data: Union[bytes, Iterable[bytes]]) -> bytes: """Return bytes as is; "flatten" iterable of bytes.""" if isinstance(data, bytes): return data elif isinstance(data, Iterable): return b''.join(data) else: raise TypeError from typing...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6231.py
Python
x: List[int] = [] # do something with x x = [] # Error: need annotation
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6232.py
Python
if foo(): x = 0 print(x) else: x = 'a' # Define a new variable? print(x) for x in [1, 2]: print(x) if foo(): for x in ['a', 'b']: # Define a new variable? print(x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6233.py
Python
if foo(): x = 0 # Type of x is 'int' here else: x = '' # No error here # Type of x is 'str' here reveal_type(x) # Union[int, str]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6244.py
Python
from typing import TypeVar, Type import abc X = TypeVar("X", bound='Test') class Test(abc.ABC): @abc.abstractclassmethod def test(cls: Type[X]) -> X: # The erased type of self "Type[t.Test]" is not a supertype of its class "t.Test" raise NotImplementedError @classmethod def test(cls: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6303.py
Python
def func() -> None: x x = 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6305.py
Python
import re from typing import Optional, Any def test(y: Optional[str]) -> Any: if y: return lambda x: not re.search(y,x) # This is fine def test2(y: Optional[str]) -> Any: if y: return filter(lambda x: not re.search(y,x), ["1", "2"]) #raises an error
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6328.py
Python
from typing import Any, List a = 0 # type: Any x = filter(None, reveal_type(a)) # type: List[str] # Error x2 = filter(None, a) # type: List[str] # No error
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6338.py
Python
class C: def f(self) -> None: self.x: D = D() # Expression has type "D", variable has type "int" self.x: int class D: pass reveal_type(C().x) # int
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6366.py
Python
def assert_never(x: Any) -> NoReturn: assert False, "Unhandled type: {}".format(type(x).__name__) PetLiteral = Literal['dog', 'cat', 'iguana'] def make_sound_literal(pet: PetLiteral) -> str: if pet == 'dog': return 'woof' elif pet == 'cat': return 'meow' # elif pet == 'iguana': # ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6387.py
Python
Types = Union[int, str] T = TypeVar('T', bound=Types) class A: x: Types y: Type[Types] class B(A, Generic[T]): x: T # ok y: Type[T] # error: Incompatible types in assignment
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6393.py
Python
from typing_extensions import Protocol class SomeProto(Protocol): var: int class Meta: abstract = True class SomeImpl: def __init__(self) -> None: var = 5 def a_func(a: SomeProto) -> None: pass a_func(SomeImpl())
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6422.py
Python
class Out: def meth(self) -> None: class In: def meth(self) -> None: class C: pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6440.py
Python
from typing import Callable, Iterable, Mapping, MutableMapping, TypeVar, List, cast T = TypeVar('T') Tk = TypeVar('Tk') Tv = TypeVar('Tv') def group_by( items: Iterable[T], *, key: Callable[[T], Tk], value: Callable[[T], Tv] = lambda x: cast(Tv, x), ) -> Mapping[Tk, Iterable[Tv]]: result: MutableM...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6457.py
Python
from typing import List x: List[List[str]] = [*([1] for i in range(10))]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6459.py
Python
class Foo(): var = 1 class Bar(Foo): def __init__(self, x): pass (cls.var for cls in (Foo, Bar))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6462.py
Python
from mypy_extensions import TypedDict A = TypedDict( 'A', { 'foo': int, 'bar': int, } ) B = TypedDict( 'B', { 'foo': int, } ) a = A({'foo': 1, 'bar': 2}) b = B({'foo': 2}) a.update({'foo': 2}) a.update(b)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6463.py
Python
from typing import * def foo() -> Dict[str, Any]: return {} def bar() -> Union[Dict[str, Any], Dict[int, Any]]: return {}
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6464.py
Python
from abc import ABC from typing import List class MyBase(ABC): ... class A(MyBase): ... class B(MyBase): ... def foo() -> None: txns: List[MyBase] = [] reveal_type(txns) txn = txns[0] reveal_type(txn) assert isinstance(txn, A) reveal_type(txn) # This next line is optional. Both...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6473.py
Python
class A(object): NAME = __qualname__
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6478.py
Python
from typing import List, Union def f(x: Union[int, List[int]]) -> None: # `TypeVar` can fix it x + x
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6482.py
Python
from typing import Generic, TypeVar T_contra = TypeVar('T_contra', contravariant=True) class Animal: pass class Cat(Animal): pass class AnimalBox(Generic[T_contra]): def __init__(self, animal: T_contra): pass def print_box(a: AnimalBox[Cat]): pass animal = Animal() print_box(AnimalB...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6483.py
Python
from mypy_extensions import TypedDict class FooBase(TypedDict): x: int # a required field class Foo(FooBase, total=False): y: int # an optional field f = Foo(x=5) # current situation f['x'] # ok f['y'] # ok f.get('y', 0) # ok # "strict" situation f['x'] # ok (item is always present) f['y'] # FAIL f....
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6501.py
Python
django.db.models.fields.CharField[Union[builtins.str, builtins.int, django.db.models.expressions.Combinable], builtins.str] def make_queryset_repr_return_only_one_type(): from mypy.types import TypeStrVisitor old_visit_instance = TypeStrVisitor.visit_instance def patched_visit_instance(self, t: Instance)...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6509.py
Python
from typing import Dict, Generic, TypeVar Key = TypeVar('Key') class A(Generic[Key]): @staticmethod def lookup(d: Dict[Key, int], key: Key) -> None: x = d.get(key, 0) + 1 x = 1 + "a"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6514.py
Python
from typing import Generic, TypeVar, overload, Any, Union import datetime as dt T = TypeVar('T') class Column(Generic[T]): @overload def __get__(self, instance: None, owner: Any) -> "Column[T]": ... @overload def __get__(self, instance: object, owner: Any) -> T: ... def __get__(self, instance: Un...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6520.py
Python
from typing import TypeVar, Generic T = TypeVar('T') class A: def __init__(self, x: T) -> None: self.x = x def get(self) -> T: return self.x x: int = A('lol').get()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6526.py
Python
lx: Optional[Tuple[str, int]] = None lx[0] reveal_type(lx)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6577.py
Python
TestOne = TypedDict('TestOne', {'test': int, 'another': str}, total=False) TestTwo = TypedDict('TestTwo', {'test': int}, total=False) var_1: TestOne = {'test': 1, 'another': 'hi'} var_2: TestTwo = var_1 # Doesn't cause a type error... why not?? 'another' is not a valid key on a TestTwo var_3: TestTwo = { # Does caus...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6583.py
Python
from typing import no_type_check, no_type_check_decorator @no_type_check_decorator def test(fn): return fn @test def blah(x: {'x': 1}): pass @no_type_check def blah2(x: {'x': 1}): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6610.py
Python
from typing import Callable def dec(f) -> Callable[[int], None]: pass x = int() if x: def f(x: str) -> None: pass else: # No complaint about incompatible redefinition! @dec def f(): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6623.py
Python
# foobar.py from typing import NamedTuple, overload A = NamedTuple("A", (("f", int),)) B = NamedTuple("B", (("q", int),)) @overload def plain(a: A) -> int: ... @overload def plain(a: B) -> str: ... def plain(a): if isinstance(a, A): return 4 elif isinstance(a, B): return "4" el...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6647.py
Python
def test() -> None: print(e) try: pass except Exception as e: pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6653.py
Python
# [file a/mod.py] # empty # [file b/mod.py] 42 + 'no'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6656.py
Python
from __future__ import annotations from typing import NamedTuple, Protocol, Optional class Simple: two: Optional[int] def as_simpl_verified(self) -> SimpleVerified: assert self.two is not None return self class SimpleVerified(Protocol): two: int
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6670.py
Python
class Container: value: int = 0 def __init__(self, value: int = 0): self.value = value def __and__(self, other: 'Container') -> 'Container': return add_gate_to_cnf('and', self.value, other.value) def __str__(self) -> str: return str(self.value) def i_and(left: Union[bool, Con...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6680.py
Python
from typing import Any, Dict, Tuple x = (1,2) isinstance(x, tuple) isinstance(x, Tuple[Any, ...]) isinstance(x, Tuple)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6697.py
Python
map(abs, [1]) map(lambda x: abs(x), [1])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6701.py
Python
from bson import ObjectId UserId = NewType('UserId', ObjectId)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6709.py
Python
class A: def f(self, x: int) -> None: print("A: ", x) class B(A): def f(self, x: int) -> None: print("B: ", x) class C(A): def f(self, n: int) -> None: print("C: ", n) a = A() a.f(x=3) b = B() # type: A b.f(x=3) c = C() # type: A c.f(x=3) # mypy passes, but gives runtime error: Typ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6713.py
Python
from unittest.mock import MagicMock class Foo: def bar(self) -> None: pass foo = Foo() foo.bar = MagicMock() foo.bar() foo.bar.assert_called()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6715.py
Python
import attr @attr.s class MyData: is_foo: bool = attr.ib() @staticmethod def is_foo(string: str) -> bool: return False
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6727.py
Python
from typing import Tuple, Dict, Any def exec(args: Tuple, kwargs: Dict[str, Any]): action_id = 0 action_name = "exec" _command_fallback(*args, __action_id=action_id, __action_name=action_name, **kwargs) def _command_fallback(self, *args, __action_id: int, __action_name: str, **kwar...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6730.py
Python
from typing import Any, Generic, Iterable, TypeVar, Union ValueT = TypeVar('ValueT') class Recursive(Iterable[Union[ValueT, 'Recursive[ValueT]']]): pass class Base(Generic[ValueT]): def __init__(self, element: ValueT): pass class Sub(Base[Union[ValueT, Recursive[ValueT]]]): pass x: Iterable[str...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6746.py
Python
from abc import * from fractions import * from typing import * Input = TypeVar('Input') Output = TypeVar('Output') class Base(Generic[Input, Output]): def do(self, input: Input) -> Output: # In reality do a bit more than just call "_operator". return self._operator(input) @abstractmethod ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6748.py
Python
from typing import Generic, TypeVar, Callable R = TypeVar('R') L = TypeVar('L') T = TypeVar('T') E = TypeVar('E') class Either(Generic[L, R]): def map(self, f): # type: (Callable[[R], T]) -> Either[L, T] # reveal_type(self.bimap) # a # return self.bimap(lambda x: x, f) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6751.py
Python
from typing import Optional, Union, TypeVar MyUnion = Union[int, str] T = TypeVar("T") def not_none(x: Optional[T]) -> T: assert x is not None return x # Works def f(i: Optional[int]) -> int: return not_none(i) # Doesn't work def g(u: Optional[MyUnion]) -> MyUnion: return not_none(u)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6760.py
Python
from pathlib import Path @pytest.fixture def db_path(tmp_path: Path) -> Path: return tmp_path / 'test.db'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6799.py
Python
from typing import Union, Tuple def get_tuple() -> Union[Tuple[int, int], Tuple[None, None]]: return (1, 2) def process_tuple(one, two, flag=False): print(one, two, flag) process_tuple(*get_tuple(), flag=True)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6801.py
Python
from abc import abstractmethod from typing import TypeVar from attr import attrs from typing_extensions import Protocol T = TypeVar("T") @attrs(auto_attribs=True) class Test(Protocol[T]): a: int @abstractmethod def transition_to(self, t: T): raise NotImplementedError
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6816.py
Python
# main.py import a reveal_type(a.b) # file a/__init__.py from a.c import C # file a/b.py class B: ... # file a/c.py from a.b import B class C: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6824.py
Python
from typing_extensions import Literal from typing import Union HTTPMethodName = Union[ Literal['GET'], Literal['POST'], ] class A: method: HTTPMethodName class B(A): # works if the subclass also annotates the property method: HTTPMethodName = 'POST' class C(A): # error: Incompatible typ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6831.py
Python
x = 123 from m1 import x __all__ = [] from m2 import x __all__ = ['x'] x: int from m2 import x as x from m1 import x as x
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6835.py
Python
from typing import Optional def get_org_id(org_name: str) -> str: return 'some_org_id' def create(org_name: Optional[str], org_id: Optional[str]): if not org_name and not org_id: raise ValueError('No org specified') if not org_id: org_id = get_org_id(org_name)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6895.py
Python
from typing import Callable, Optional, Tuple, Pattern, Union, TypeVar, Generic, Text S = TypeVar('S') T = TypeVar('T') A = TypeVar('A') B = TypeVar('B') class ParserState(Generic[S, T]): pass ParseResult = Optional[Tuple[A, ParserState[S, T]]] Parser = Callable[[ParserState[S, T]], ParseResult[A, S, T]] # th...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli