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/3000-3999/3172.py | Python | from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
def f(self) -> None:
x: T
from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
@staticmethod
def f() -> None:
x: T # Error we don't yet provide: Invalid type "__main__.T"
from typing import T... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3178.py | Python | from typing import TypeVar, Callable
class Summable: ...
class MySummable(Summable): ...
T = TypeVar('T', bound=Summable)
def plus(a: T, b: T) -> T: ...
def plus_partial(t: T) -> Callable[[T], T]:
def f(t1: T) -> T:
return plus(t1, t)
return f
my_s: MySummable
plus_my_s = plus_partial(my_s)
s: Summa... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3183.py | Python | from typing import *
T = TypeVar('T', bound='A')
class X: ...
class Y(X): ...
class A(Iterable[X]):
def __iter__(self) -> Iterator[X]: ...
class B(A, Iterable[Y]):
def __iter__(self) -> Iterator[Y]: ...
b = B()
for x in b:
reveal_type(x) # 'Y*'
y = list(b)
reveal_type(y) # 'builtins.list[X*]'
z = ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3194.py | Python | from typing import Any
x = 'a'
y: Any = 1
lst = [x, y]
lst[0] >> 1 # not detected by mypy, fails at runtime, will be fixed by rule (3)
def f(x: int) -> None:
x >> 1
def g(x: Any) -> None:
pass
funs = [f, g]
funs[0]('a') # not detected by mypy, fails at runtime, will be fixed by rule (4)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3208.py | Python | class A:
x: float
class B(A):
x: int # no error, though unsafe
def f(a: A) -> None:
a.x = 1.1
b = B()
f(b)
b.x # float at runtime, though declared as int
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3224.py | Python | def foo(a: int, b: str = '') -> None: ...
foo(1) # OK
foo(*[1]) # E: Argument 1 to "foo" has incompatible type *List[int]; expected "str"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3229.py | Python | def foobar(foo: Union[str, float]):
if foo in ['fizz', 'buzz']:
reveal_type(foo)
else:
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3258.py | Python | from typing import Union
Union[123]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3283.py | Python | from datetime import datetime, timedelta
data_dic = {idx: []
for idx in range(len(lcl.msgs['DATA_COL_NAMES']) - 1)} # type: Dict[int, List[Union[datetime, float]]]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3284.py | Python | row = 0 # type: int
# do some processing with the row var
row, event = some_func() # type: int, List[str]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3297.py | Python | def is_subtype(left, right):
if isinstance(left, AnyType) or isinstance(right, AnyType):
return True
return is_proper_subtype(left, right)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3331.py | Python | from typing import *
SortedList = NewType('SortedList', List)
A = TypeVar('A')
def my_sorted(items: List[A]) -> SortedList[A]:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3339.py | Python | lst1 = [1, 'a', None]
lst2 = [1, None, 'a']
reveal_type(lst1) # builtins.list[builtins.object*]
reveal_type(lst2) # builtins.list[Union[builtins.str, builtins.int, builtins.None]]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3345.py | Python | # Currently supported:
Tuple[int, int, int] # A tuple of 3 ints
Tuple[int, ...] # A tuple of any number of ints
# Proposed:
Tuple[int, 256] # A tuple of 256 ints
# Currently supported:
SboxType = Tuple[
Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],
Tuple[int, int, int,... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3370.py | Python | y: List[Tuple[int]]
reveal_type(zip(*y)) # Revealed type is 'Any'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3431.py | Python | if message is None:
message = Message.objects.select_related().get(id=message_id)
rendered_content = render_markdown(message, content, realm=message.get_realm())
if message is None:
message = Message.objects.select_related().get(id=message_id)
assert message is not None # ADDED
rendered_content = render_... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3475.py | Python | x = 0
a = [x]
from typing import List
x: int
a: List[int]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3482.py | Python | class A:
@classmethod
def hi(cls):
pass
bye = classmethod(hi.__func__)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3500.py | Python | if random() > 0.5:
import mod1
else:
import mod2 as mod1
try:
import fastmath
except ImportError:
import math as fastmath
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3506.py | Python | from typing import *
T = TypeVar('T')
def f(a: Union[List[int], T]) -> T: pass
f([1]) # OK
f(['']) # E: List item 0 has incompatible type "str" <<--- unexpected
a = ['']
f(a) # OK
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3551.py | Python | noop_ctxmgr = contextmanager(lambda: (yield))
@contextmanager
def noop_ctxmgr():
yield
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3568.py | Python | from typing import TypeVar, Generic, Callable
A = TypeVar('A')
B = TypeVar('B')
E = TypeVar('E', bound=BaseException)
class Child(Generic[A]):
def __init__(self, x):
# type: (E) -> None
self.x = x
def fun(self, s, f):
# type: (Callable[[A], Child[B]], Callable[[E], Child[B]]) -> Chil... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3587.py | Python | class Foo:
pass
Base = Foo
class Types:
Base = Foo
reveal_type(Base)
reveal_type(Types.Base)
class Works(Base):
pass
class Fails(Types.Base):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3644.py | Python | from typing import TypeVar, Generic, Union
AnyStr = TypeVar('AnyStr', str, bytes)
class PathLike(Generic[AnyStr]):
def __fspath__(self) -> AnyStr: ...
def readlink(s: Union[AnyStr, PathLike[AnyStr]]) -> AnyStr:
...
class BP(PathLike[bytes]):
def __fspath__(self) -> bytes:
return b''
class SP(Pa... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3717.py | Python | --linecount-report
--txt-report
--txt-report | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3724.py | Python | from typing import Any, Optional
def foo() -> Optional[int]:
return 42
raz: Any
def bar() -> int:
x = foo()
if isinstance(x, int):
reveal_type(x)
x = raz()
reveal_type(x)
x = x + 42
return 0
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3737.py | Python | from typing import TypeVar
_T = TypeVar('_T')
def foo(a: _T = 42) -> _T: # E: Incompatible types in assignment (expression has type "int", variable has type "_T")
return a
_T = TypeVar('_T')
def noop_parser(x: str) -> str:
return x
def foo(value: str, parser: Callable[[str], _T] = noop_parser) -> _T:
re... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3750.py | Python | KeyTy = TypeVar("KeyTy")
ValTy = TypeVar("ValTy")
TempTy = TypeVar("TempTy")
class CIDict(Dict[KeyTy, ValTy]):
@overload
def pop(self, key: KeyTy) -> ValTy:
pass
@overload
def pop(self, key: KeyTy, default: Union[ValTy, TempTy]) \
-> Union[ValTy, TempTy]:
pass
def pop(... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3775.py | Python | class A(object):
def float(self):
# type: () -> float
return 1.0
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3816.py | Python | x = [1, 'a']
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3819.py | Python | from typing import *
@overload
def f(arg: str = "foo") -> AbstractSet[Tuple[str, str]]: ...
@overload
def f(arg: int = 0) -> AbstractSet[Tuple[str, Tuple[str, int]]]: ...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3829.py | Python | class P(Protocol[T_co]):
def meth(self) -> P[T_co]: ...
class C(Generic[T]):
def meth(self) -> C[T]: ...
def fun(arg: P[T]) -> T: ...
x: C[int]
reveal_type(f(x)) # I think this should be 'int'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3853.py | Python | from multipledispatch import dispatch
@dispatch(int)
def foo(x: int) -> None:
print('int')
@dispatch(str)
def foo(x: str) -> None:
print('str')
foo(1) # Prints 'int'.
foo('a') # Prints 'str'.
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3860.py | Python | from typing import Callable, Optional, Type
from mypy.plugin import MethodContext, Plugin
class DummyPlugin(Plugin):
def get_method_hook(
self, fullname: str) -> Optional[Callable[[MethodContext], Type]]:
return dummy_callback
def dummy_callback(ctx: MethodContext) -> Type:
return ctx.... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3863.py | Python | R = TypeVar("R")
FileCachedData = TypedDict('FileCachedData', {'mtime': float, 'size': int, 'value': R})
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3884.py | Python | from typing import Tuple, Dict
from itertools import product
# works fine
XY_1: Dict[str, Tuple[int, int]] = dict(zip('abcd', product(range(2), range(2))))
# {'a': (0, 0), 'b': (0, 1), 'c': (1, 0), 'd': (1, 1)}
# error for this one
XY_2: Dict[str, Tuple[int, int]] = dict(zip('abcd', product(range(2), repeat=2)))
# {'... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3903.py | Python | Any
class A:
def foo(self, a: str) -> None: pass
class B(A):
def foo(self, a):
reveal_type(a)
Any
str | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3904.py | Python | import sys
from typing import TypeVar, Generic, overload
assert sys.version_info >= (3, 5)
class Foo(object):
def __init__(self, dummy):
self.dummy = dummy
class Bar(object):
def __init__(self, dummy):
self.dummy = dummy
class Apple(object):
def __init__(self, dummy):
self.dum... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3924.py | Python | from typing import TypeVar, Callable
T = TypeVar('T')
def test1() -> Callable[[T], T]: ...
reveal_type(test1) # Revealed type is 'def () -> def [T] (T`-1) -> T`-1'
reveal_type(test1()) # Revealed type is 'def [T] (T`-1) -> T`-1'
F = Callable[[T], T]
def test2() -> F[T]: ...
reveal_type(test2) # Revealed type is 'def ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3935.py | Python | from typing import cast, List, Union
Scalar = Union[str, float]
def good() -> List[Scalar]:
return ["foo", 1.0]
def bad(params: List[Scalar]) -> List[Scalar]:
# error: Incompatible return value type (got List[object], expected
# List[Union[str, float]])
# error: Unsupported operand types for + (Lis... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3946.py | Python | from typing import *
U = Union[int, str]
d: Dict[Type[U], int] = {int: 1, str: 2}
T = TypeVar('T', bound=U)
def get(t: Type[T]) -> int:
return d[t]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3948.py | Python | def f():
a: int = 'x' # Maybe this annotation should be an error?
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3951.py | Python | from typing import Type, Any
def generate_str(cls: Type) -> Type:
"""
Class decorator that auto generates __str__().
:param cls: class to modify
:return: modified class
"""
def __str__(self) -> str:
return _pretty_print_obj(self)
cls.__str__ = __str__
return cls
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3955.py | Python | from typing import Iterable, Iterator, Tuple, TypeVar
T = TypeVar('T')
S = TypeVar('S')
class C(Iterable[Tuple[T, S]]):
def __iter__(self) -> Iterator[Tuple[T, S]]: pass
def f(*x: T) -> T: pass
x: C[str, int]
y: C[int, int]
reveal_type(f(*x)) # str, should be Tuple[str, int]
reveal_type(f(*y)) # int, should b... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3964.py | Python | from typing import Union
def f(a: Union[str, int]):
if a == 'a':
reveal_type(a) # expect str
str.lower(a)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3976.py | Python | from typing import Type, Optional
class Foo:
pass
def make_foo(cls: Optional[Type[Foo]] = None) -> Foo:
x = Foo if cls is None else cls
reveal_type(x)
return x()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3983.py | Python | type_map = {int: 42}
t = type_map[int]
type_map: Any
t = type_map[int]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/3000-3999/3993.py | Python | from typing import *
class Foo:
class Bar:
pass
def __init__(self) -> None:
self._bar = None
def start(self) -> None:
self._bar = self.Bar()
self._bar = None # type: Bar
self._bar = None # type: self.Bar
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4019.py | Python | class C:
x: int
c = C()
c.x
y: str
y
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4063.py | Python | from typing import Union, NoReturn, overload
@overload
def assert_int(x: int) -> None: ...
@overload
def assert_int(x: str) -> NoReturn: ...
def assert_int(x):
assert isinstance(x, int)
y: Union[int, str]
assert_int(y)
reveal_type(y) # should be: int; currently Union[int, str]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4088.py | Python | from typing import Optional
def f() -> None:
a = None
while True:
g(a) # <-- No error here!
a = [1]
def g(a: Optional[str]) -> None:
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4122.py | Python | from mypy_extensions import TypedDict
Details = TypedDict('Details', {'first_name': str, 'last_name': str})
DetailsSubset = TypedDict('DetailsSubset', {'first_name': str, 'last_name': str}, total=False)
defaults = {'first_name': 'John', 'last_name': 'Luther'} # type: Details
def generate(data: DetailsSubset) -> Det... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4125.py | Python | class Foo:
def __init__(self) -> None:
self.x = 42
class Bar(Foo):
def __init__(self) -> None:
self.y = 9000
@property
def x(self) -> int:
print('got x!!!')
return self.y
@x.setter
def x(self, value: int) -> None:
print('set x!!!')
self.y = valu... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4128.py | Python | from mypy_extensions import TypedDict
Details = TypedDict('Details', {'name': str, 'age': int, 'address': str})
DetailsSubset = TypedDict('DetailsSubset', {'name': str, 'age': int, 'address': str}, total=False)
from mypy_extensions import TypedDict
keys = {'name': str, 'age': int, 'address': str}
Details = TypedDict... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4134.py | Python | from typing import AnyStr
def f(x: AnyStr) -> bytes:
return x.encode("ascii") if isinstance(x, str) else x
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4144.py | Python | from .b import *
from .c import *
from ._b import *
import top
class Cls:
pass
from . import b
foo: b.Cls = None
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4146.py | Python | from . import bar
class Foo:
def bar(arg: bar.Spam):
pass
class Spam:
pass
from . import bar
def bar(arg: bar.Spam):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4150.py | Python | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import reduce
from typing import Iterable
def update(ccc: dict, meta: dict) -> dict:
foo = dict(ccc)
foo.update(meta)
return foo
def reduce_func(configs: Iterable[dict]) -> dict:
output = dict(reduce(update, configs, {})) # type: dict
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4165.py | Python | from abc import abstractmethod
class A:
@property # error occurs here
@abstractmethod
def foo(self) -> int:
pass
@foo.setter # type: ignore
@abstractmethod
def foo(self, value: int) -> None:
pass
mypy --strict
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4168.py | Python | from typing import Optional
class Foo:
bar: Optional[int]
def thing(self) -> int:
if self.bar is None:
return 0
self.set_bar_to_none()
return self.bar
def set_bar_to_none(self) -> None:
self.bar = None
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4177.py | Python | from typing import Any
class Foo:
def foo(self, x:Any) -> bool:
return isinstance(x, __class__)
if TYPE_CHECKING:
__class__ : Type
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4179.py | Python | import sys
from typing import List
from mypy_extensions import NoReturn
def never_returns() -> NoReturn:
sys.exit(1)
def foo() -> None:
x = never_returns()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4266.py | Python | class Foo:
__hash__ = None
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4272.py | Python | from typing import TypeVar, Type, Iterable, Iterator
T = TypeVar('T')
class M(type):
def __iter__(self: Type[T]) -> Iterator[T]: raise Exception
class A(metaclass=M): pass
x: Iterable[A] = A # fine
y: Iterable[str] = A # should be rejected, but it is not
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4285.py | Python | class BoundedMeta(type):
def __getitem__(self, args):
...
class Bounded(metaclass=BoundedMeta):
...
Age = Bounded[int, 0:150]
class Person:
age: Age
class Person:
age: Bounded[int, 0:150]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4297.py | Python | from typing import Optional, Callable
def f1(key: Callable[[], str]) -> None: ...
def f2(key: object) -> None: ...
def g(b: Optional[str]) -> None:
if b:
f1(lambda: b.upper()) # Item "None" of "Optional[str]" has no attribute "upper"
z: Callable[[], str] = lambda: b.upper() # Item "None" of "Opt... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4306.py | Python | i = 0
assert isinstance(i, str) # error
assert type(i) is str # error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4330.py | Python | d = {k: v for k, v in []}
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4335.py | Python | from typing import Any, Dict, Optional, Sequence, Tuple
class BaseClass(object):
def __init__(self, foo: str, *args: Sequence[Any], **kwargs: Dict[str, Any]) -> None:
self.foo = foo
super().__init__(*args, **kwargs)
class Mixin(object):
def __init__(self, bar: str, baz: Optional[str]=None, *ar... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4359.py | Python | from typing import Dict
def foo(x: Dict) -> str:
result = x.get('foo', None)
reveal_type(result) # E: Revealed type is 'Any'
return result
from typing import Dict
def foo(x:Dict) -> str:
result = x.get('foo')
reveal_type(result) # E: Revealed type is 'Union[Any, builtins.None]'
return resul... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4373.py | Python | class Base:
def foo(self): pass
class Mix: pass
class A(Mix, Base): pass
class B(Mix, Base): pass
def foo() -> None:
a = A() if bool() else B()
reveal_type(a) # Shows Mix
a.foo() # E: "Mix" has no attribute "foo"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4374.py | Python | mac_value = int(mac.translate(str.maketrans(dict([(x, None) for x in [" ", ".", ":", "-"]]))), 16)
trans = str.maketrans(dict([(x, None) for x in [" ", ".", ":", "-"]]))
mac_value = int(mac.translate(trans), 16)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4402.py | Python | from typing import TypeVar , Tuple, Generic, Iterable, Callable
T = TypeVar('T', covariant=True)
S = TypeVar('S')
class _Base(Generic[T]):
@classmethod
def split(self, left, right):
# type: (_Base[S], _Base[T]) -> _Base[Tuple[S, T]]
return Split(left, right)
@classmethod
def merge_cl... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4409.py | Python | def f():
return "hello"
def g(x):
if x: return A(1)
else: return A(2)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4416.py | Python | class A:
x = None
y = None
def __init__(self): # Note: no annotation
self.x = 1
def g(self) -> None:
self.y = 1
a = A()
reveal_type(a.x) # None <---- unexpected
reveal_type(a.y) # Union[int, None]
if a.x is not None:
1 + '' # No error, because mypy considers this unreachable... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4425.py | Python | from typing import TypeVar, Any, Callable, AnyStr
F = TypeVar('F', bound=Callable)
def on_exception_return(to_return):
# type: (Any) -> Callable[[F], F]
pass
@on_exception_return(False)
def is_on(feature_name):
# type: (AnyStr) -> bool
return True
class A: pass
class B: pass
X = TypeVar('X', A, B)
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4426.py | Python | class P(Protocol):
x: int # Note, no r.h.s.
class C(P):
pass
class D(P):
def __init__(self) -> None:
self.x = 42
C() # E: Cannot instantiate abstract class 'C' with abstract attribute 'x'
D() # OK
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4427.py | Python | from typing import *
from typing_extensions import Protocol
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4437.py | Python | from typing import Any
def foo(
**kw # type: **Any
): # type: (...) -> int
return 1
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4455.py | Python | d = {}
e = {}
def f():
d['x'] = 1
d['y'] = 2
e['y'] = 2
reveal_type(d) # dict[Any, Any]
reveal_type(e) # dict[str, int]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4484.py | Python | x = None
def f() -> None:
reveal_type(x) # None
if x:
1() # No error, considered as not reachable
y = 1
else:
y = '' # No error
x = 1
reveal_type(x) # int
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4507.py | Python | from typing import NamedTuple
class Foo(NamedTuple):
index: str
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4530.py | Python | from typing import Callable, Union
from mypy_extensions import Arg
def f(x: Callable[[Arg(int, 'x')], None]) -> None: pass
y: Callable[[Union[int, str]], None]
f(y) # error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4531.py | Python | from typing import Callable
from mypy_extensions import Arg
x: Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]
y: Callable[
[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]
x = y
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4536.py | Python | from typing_extensions import Protocol
class Jumps(Protocol):
def jump(self) -> int:
pass
class Jumper1:
@classmethod
def jump(cls) -> int:
print("class jumping")
return 1
class Jumper2:
def jump(self) -> int:
print("instance jumping")
return 2
def do_jump(j: ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4547.py | Python | from typing import List
class A:
x: List[str]
class B(A):
x = [] # Need type annotation
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4551.py | Python | import collections
from typing import Any, Dict, Text
class PlainOldData:
def as_json_dict(self) -> Dict[Text, Any]:
result = collections.OrderedDict()
for k in self.__slots__:
value = getattr(self, k)
if value is not None:
result[k] = value
return r... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4554.py | Python | # Run with --strict-optional
from typing import TypeVar, Callable, Optional, List
_T = TypeVar('_T')
def make(typ: Callable[[], _T]) -> _T:
...
def accept(arg: Optional[_T]) -> _T:
...
accept(make(list))
accept(None)
foo = accept(make(list)) # This works
bar: List[str] = accept(make(list)) ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4572.py | Python | class Immutable:
def __setattr__(self, attr: str, val: Any) -> NoReturn:
raise AttributeError("Not with this class!")
class C(Immutable):
def __init__(self, val: int) -> None:
object.__setattr__(self, 'val', val)
c = C(42)
if random() < 0.001:
c.val = 0 # Ideally mypy should say 'Class "C... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4574.py | Python | class Base(object):
def foo(self):
# type: () -> None
a = self.static_foo()
class SubClass(Base):
static_foo = staticmethod(lambda: 5)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4625.py | Python | from typing import Optional, Type, Any, TypeVar
T = TypeVar('T')
def structure(obj: Any, type: Type[T]) -> T:...
reveal_type(structure('foo', str)) # Revealed type is 'builtins.str*'
reveal_type(structure('foo', Optional[str])) # Revealed type is 'Any'
@typing.castlike
def structure(obj: Any, type: Type[T]) -> T:.... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4644.py | Python | class A(object):
__metaclass__ = ABCMeta
@property
def prop(self):
# type: () -> int
return 1
class B(A):
@A.prop.setter
def prop(self, val):
# type: (int) -> None
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4654.py | Python | class Type(enum.Enum):
EMPTY = 0
name = 1
datasetConfig = 2
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4676.py | Python | _SysExcInfoType = Union[Tuple[type, BaseException, TracebackType],
Tuple[None, None, None]]
if sys.version_info >= (3, 5):
_ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException]
else:
_ExcInfoType = Union[None, bool, _SysExcInfoType]
def log(self,
lvl: int, msg... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4717.py | Python | import abc
import typing
class FooObserver(metaclass=abc.ABCMeta):
"""Receives Foo events."""
@abc.abstractmethod
def on_foo(self, count: int) -> None:
raise NotImplementedError()
class BarObserver(metaclass=abc.ABCMeta):
"""Receives Bar events."""
@abc.abstractmethod
def on_bar(self... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4727.py | Python | class A:
def hello(self) -> None:
if self.x:
self.x = False
def world(self) -> None:
self.x = True
class A:
def world(self) -> None:
self.x = True
def hello(self) -> None:
if self.x:
self.x = False
class A:
def hello(self) -> None:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4771.py | Python | def foo(x: int, y: str) -> None: pass
t = ('hi', 12)
foo(*t)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4791.py | Python | class C:
def m(self) -> bool:
return NotImplemented
from typing import Union
class C:
def m(self) -> Union[bool, type(NotImplemented)]:
return NotImplemented
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4805.py | Python | from typing import Dict, Optional
d: Dict[str, str] = {}
def foo(arg: Optional[str] = None) -> None:
if arg is None:
arg = d.get("a", "foo bar")
print(arg.split())
d: Dict[str, str] = {}
a: str = d.get("a", "a")
d: Dict[str, str] = {}
def foo(arg: Optional[str] = None) -> None:
if arg is None:... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/4000-4999/4834.py | Python | from typing import *
class A:
a = None # type: List[str]
b = None # type: List[Union[str, int]]
c = None # type: List[Union[str, int]]
d = None # type: Sequence[Union[str, int]]
class B(A):
a = ['foo']
b = ['foo']
c = ['foo', 1]
d = ['foo', 1]
reveal_type(B.a) # 'builtins.list[bu... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.