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/8000-8999/8213.py | Python | import typing
def round_it(x: typing.SupportsRound[int]) -> int:
return round(x)
round_it(3.2)
@overload
def __round__(self, ndigits: None = ...) -> int: ...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8220.py | Python | import pathlib
p = pathlib.Path(".")
print(p)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8226.py | Python | import itertools
from typing import List
x: List[int] = [1, 2, 3]
y: List[str] = [" ", "", "abc"]
it = itertools.chain(x, filter(lambda s: s.strip() == "", y))
reveal_type(it)
f = filter(lambda s: s.strip() == "", y)
it = itertools.chain(x, f)
reveal_type(it)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8228.py | Python | from typing import Generic, Any, TypeVar, List, Dict, cast, Callable
import dataclasses
MetaDataType = TypeVar('MetaDataType')
@dataclasses.dataclass
class Item(Generic[MetaDataType]):
value: int
metadata: MetaDataType
ItemType = TypeVar('ItemType', bound = Item)
# Generic[ItemType[MetaDataType]] fails at runt... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8234.py | Python | # test.py
import sys
assert sys.platform == "win32"
class Foo:
pass
foo = Foo()
foo.bar = 1 # type: ignore[attr-defined]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8241.py | Python | from typing import overload, Callable, Union, List, Set
@overload
def f(x: Callable[[str], str]) -> Set: ...
@overload
def f(x: Callable[..., str]) -> List: ...
def f(x: Callable[..., str]) -> Union[list, set]: ... # E: Overloaded function signatures 1 and 2 overlap with incompatible return types
def g(a: str) -> ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8247.py | Python | a = [[[[[[[[[[[[[[[[[[[[
0
]]]]]]]]]]]]]]]]]]]]
a = {0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:{0:
0
}}}}}}}}}}}}}}}}}}}}
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8252.py | Python | import abc
from typing import Generic, TypeVar
A = TypeVar('A')
class Expr(Generic[A], metaclass=abc.ABCMeta):
pass
class Const(Expr[A]):
value: A
def __init__(self, value: A):
self.value = value
class Add(Expr[int]):
left: Expr[int]
right: Expr[int]
def __init__(self, ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8265.py | Python | foo: Union[int, Callable[[Any], int]]
bar: Callable[[Any], int]
foo = lambda _: 0
# case A
# no errors:
if callable(foo):
bar = foo
else:
bar = lambda _: foo
# case B
# error: Incompatible return value type (got "Union[int, Callable[[int], int]]", expected "int")
bar = foo if callable(foo) else lambda _: foo... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8266.py | Python | from typing import List, NoReturn, Sequence
a: List[List[int]] = [] # ok
b: List[NoReturn] = [] # ok
c: List[List[NoReturn]] = [[]] # ok
d: List[List[NoReturn]] = [[]][:0] # ok
e: List[List[NoReturn]] = [] # error
f: Sequence[List[NoReturn]] = [] # ok
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8267.py | Python | class A:
def __init__(self, x: int) -> None:
self.__x = x # replace this with pass and mypy reports the error
class B(A):
def __init__(self) -> None:
A.__init__(self, self.__x)
B()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8269.py | Python | from typing import Callable, Protocol
class F(Protocol):
def __call__(self, *__args: str, __arg: int) -> int: ...
def f(*__args: str, __arg: int) -> int: ...
f_: F = f
class G(Protocol):
def __call__(self, __arg: int, *__args: str) -> int: ...
def g(__arg: int, *__args: str) -> int: ...
g_: G = g
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8275.py | Python | from typing import Callable, TypeVar, Generic
def foo() -> int:
return 1
T = TypeVar('T')
bar: Callable[[], T] = foo
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8276.py | Python | from __future__ import annotations
import asyncio
import typing as t
from contextlib import asynccontextmanager
import typing_extensions as te
class LockProto(te.Protocol):
async def with_lock(self) -> t.AsyncContextManager[str]: ...
class Consumer:
def __init__(self, locker: LockProto) -> None:
s... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8283.py | Python | from typing import Awaitable, Callable, Generic, TypeVar, overload
T = TypeVar("T", "Handler", "AsyncHandler")
Handler = Callable[[], "Result"]
AsyncHandler = Callable[[], Awaitable["Result"]]
class Result:
pass
class Middleware(Generic[T]):
def __init__(self, handler: T):
self.handler: T = handle... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8284.py | Python | def f(x: Iterable[int]) -> None:
if not x: # Might never be taken, or at least this could be inconsistently taken
print('x')
class A:
pass # No __nonzero__
def g(a: A) -> None:
if not a: # Similar to above? What if there are subclasses of 'A'?
print('x')
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8294.py | Python | from typing import List
def f(x: List[int]) -> None:
assert 'foo' not in x # Error, but should this be okay?
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8298.py | Python | class A:
def f(self, x: int, y: str, z: float) -> None: pass
class B(A):
def f( # Argument 3 incompatible with supertype "A" <-- reported here
self,
x: int,
y: str,
z: bool, # <-- would be better to report it here
) -> None:
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8317.py | Python | from typing import TypeVar
from typing_extensions import Protocol
TA = TypeVar("TA", contravariant=True)
class P(Protocol[TA]):
def __call__(self, *, a: TA, b: int) -> None: ...
def misordered(*, b: int, a: TA) -> None: ... # Should be seen as Protocol[TA]
def ordered(*, a: TA, b: int) -> None: ... # Should... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8320.py | Python | from typing import Union, List, TypeVar
SomethingWithWs = Union[str, List['SomethingWithWs']]
T = TypeVar('T', bound=SomethingWithWs)
def remove_w(data: T) -> T:
if isinstance(data, str):
return data.replace('w', '')
elif isinstance(data, list):
return [remove_w(d) for d in data]
else:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8330.py | Python | from typing import overload
from typing_extensions import Literal
class Cat:
@overload
def __new__(cls, name: Literal['Tabby']) -> 'Tabby': ...
@overload
def __new__(cls, name: Literal['Kitty']) -> 'Kitty': ...
def __new__(cls, name: str) -> 'Cat': ...
class Kitty(Cat):
pass
class Tabby(Cat... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8334.py | Python | from dataclasses import dataclass, field
@dataclass
class Base:
foo: bool = field()
@dataclass(frozen=True)
class Derived(Base):
@property
def foo(self):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8342.py | Python | from typing import TypeVar
T = TypeVar("T", bound="Number")
class Number:
def __abs__(self: T):
return self
def square(self: T) -> T:
return self
def myabs(x: T) -> T:
return abs(x)
x = myabs(Number())
x.square()
from typing import TypeVar
T = TypeVar("T", bound="Number")
class... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8355.py | Python | from typing import Union
class UserTypeA: ...
class UserTypeB: ...
class A:
def permissions_for(self, user: UserTypeA) -> bool: ...
@property
def me(self) -> UserTypeA: ...
class B:
def permissions_for(self, user: UserTypeB) -> bool: ...
@property
def me(self) -> UserTypeB: ...
de... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8358.py | Python | class Base():
__slots__: List[str] = ['foo', 'bar']
if TYPE_CHECKING:
foo: int
bar: int
class Derived(Base):
__slots__: List[str] = ['bar']
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8359.py | Python | MyQuerySet[MyModel].as_manager()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8363.py | Python | def some(a: int): ...
some(x > 1)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8376.py | Python | from typing import Dict, Any, NamedTuple
def out() -> str:
return "out"
d = {"x": 0, "y": 1}
class Test(NamedTuple):
qwer: Dict[str, Any] = {k: v for k, v in d}
from typing import Dict, Any, NamedTuple
d = {"x": 0, "y": 1}
class Test(NamedTuple):
qwer: Dict[str, Any] = {k: v for k, v in d}
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8379.py | Python | class TryWalrus:
CKEY = {
'KY': (p:='a_'),
'ANOTHER': p+'content',
}
print(TryWalrus.CKEY['ANOTHER']) # => a_content
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8385.py | Python | # module: foo.py
def foo() -> None | baz.Baz | tuple[int, int]:
...
# module: bar.py
def bar() -> ReturnType[foo.foo]:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8393.py | Python | from typing import List, Union, overload
from typing_extensions import final
class Foo:
@overload
def get(self, index: int) -> int:
...
@overload # noqa: F811
def get(self, index: slice) -> List[int]:
...
def get(self, index: Union[int, slice]) -> Union[int, List[int]]: # noqa:... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8414.py | Python | from typing import Any, TypeVar
from functools import lru_cache
T = TypeVar("T")
class SubscriptableType(type):
""" Generic metaclass for subscriptable type. """
def __init_subclass__(cls) -> None:
cls._hash = 0
@lru_cache()
def __getitem__(cls, item: Any) -> type:
body = {
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8417.py | Python | import attr
from typing import Sequence
@attr.s(auto_attribs=True)
class Foo:
things: Sequence[str]
@attr.s(auto_attribs=True)
class Bar:
things: Sequence[str] = attr.ib(converter=tuple)
@attr.s(auto_attribs=True)
class Raz:
thing: str = attr.ib(converter=str)
Foo(['hello', 'world'])
Raz('hello')
Bar([... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8435.py | Python | from dataclasses import dataclass
from typing import Generic, TypeVar, Union
T_co = TypeVar("T_co", covariant=True)
@dataclass(frozen=True)
class Foo(Generic[T_co]):
bar: T_co
def handle_foo_int(foo: Foo[int]) -> None:
pass
def handle_foo(foo: Foo[Union[int, str]]) -> None:
if isinstance(foo.bar, int)... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8439.py | Python | import dataclasses
from dataclasses import dataclass, InitVar
from functools import partial
dataclass_alias = dataclass
dataclass_partial = partial(dataclass, frozen=True)
dataclass_decorator = dataclass(frozen=True)
# 1. ok
@dataclass(frozen=True)
class X1:
value: InitVar[bool] = None
# 2. ok
@dataclasses.data... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8441.py | Python | def foo(x: FixedSequence[int, str]) -> int:
return x[0]
foo((0, ''))
foo([0, ''])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8478.py | Python | from typing import (
TypeVar,
List,
Callable,
Optional,
)
Task = TypeVar("Task")
Result = TypeVar("Result")
def run_tasks(
tasks: List[Task], worker_fun: Callable[[Task], Result]
) -> List[Optional[Result]]:
results: List[Optional[Result]] = []
toggle: bool = True
todo: Task
for ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8482.py | Python | from typing import Type
class Foo:
def __init__(self):
class Bar:
pass
self.Bar: Type[Bar] = Bar
foo = Foo()
bar: foo.Bar = foo.Bar()
reveal_type(foo.Bar)
reveal_type(bar)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8484.py | Python | def len_greater_than_three(input_list: List[int]) -> bool: # Warning: Could use read only type Sequence instead of List for parameter 1.
return len(input_list) > 3
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8493.py | Python | class Service:
def __init__():
self.another_service = Service()
def my_method() -> None:
return self.another_service.another_method_call()
self.another_service: Service = Service()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8505.py | Python | foo: bytes = bytearray()
assert isinstance(foo, bytes)
class bytes(ByteString):
...
class bytearray(MutableSequence[int], ByteString):
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8516.py | Python | from typing import Any, Generic, Callable, TypeVar
T = TypeVar('T')
class lazy:
def __init__(self, func: Callable[[Any], T]) -> None: ...
def __get__(self, inst: Any, inst_cls: Any) -> T: ...
class Haystack:
@lazy
def hasNeedles(self) -> bool:
# some expensive lookup we want to execute only o... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8519.py | Python | import typing as t
def get_print_fn(quiet: bool) -> t.Callable[..., None]:
"""Return the standard print function if quiet is False, else an empty function."""
return (lambda *args, **kwargs: None) if quiet else print
import typing as t
def get_print_fn(quiet: bool) -> t.Callable[..., None]:
"""Return the... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8521.py | Python | from typing import Callable
def bar(x): return 5
foo : Callable[[float],int]
foo = bar
foo("test")
from typing import Callable
def bar(x): return 5
foo : Callable[[float],int] = bar
foo("test")
from typing import Tuple
foo : Tuple[str,int]
foo = (1,3)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8526.py | Python | from typing import Optional, Set
class Foo:
pass
bar: Set[Optional[Foo]] = set()
baz: Set[Foo] = bar - {None}
# Incompatible types in assignment (expression has type "Set[Optional[Foo]]",
# variable has type "Set[Foo]")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8533.py | Python | # example.py
from typing import TypedDict, Literal, Union
# TypedDict interfaces with distinct tag fields.
A = TypedDict('A', {'@type': Literal['type-a'], 'value': str})
B = TypedDict('B', {'@type': Literal['type-b'], 'value': str})
# Tagged union of A and B.
C = Union[A, B]
c: C = {
'@type': 'type-a',
'valu... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8539.py | Python | from abc import abstractmethod
from functools import total_ordering
@total_ordering
class PriorityMixin:
@abstractmethod
def getName(self) -> str: ...
@abstractmethod
def getPriority(self) -> int: ...
def __hash__(self) -> int:
return hash(self.getName())
def __eq__(self, other: obj... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8540.py | Python | from typing import Any
def get_any() -> Any:
return {}
def fun(message_json) -> int:
messages = [get_any()]
messages = get_any()
if not isinstance(messages, list):
print(messages)
return 2
from typing import Any
def get_any() -> Any:
return {}
def fun(message_json) -> int:
messa... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8541.py | Python | from typing import Tuple, Type, TypeVar
CoordsT = TypeVar('CoordsT', bound='Coords')
class Coords(Tuple[float, float, float]):
def __new__(cls: Type[CoordsT]) -> CoordsT:
reveal_type(super().__new__)
# Revealed type is 'def [_T] (cls: Type[_T`-1], iterable: typing.Iterable[_T_co`1] =) -> _T`-1'
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8543.py | Python | class C:
x: int
__hash__ = object.__hash__
from typing import NamedTuple
class C(NamedTuple):
x: int
__hash__ = object.__hash__
# mypy is ok with this
from typing import NamedTuple
class C(NamedTuple):
x: int
def __hash__(self) -> int:
return object.__hash__(self)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8556.py | Python | from typing import Any
from typing import Protocol
from typing import runtime_checkable
from typing import Type
from typing import TypeVar
from typing import Union
T = TypeVar("T", bound=Any)
@runtime_checkable
class Parsable(Protocol):
@classmethod
def parse(cls: Type[T], data: Any) -> T:
...
R = ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8586.py | Python | from typing import Sequence, Union
def baz(idx: int, arg: Union[int, str]) -> None:
pass
def foo(the_list: Union[Sequence[int], Sequence[str]]) -> None:
for idx, val in enumerate(the_list):
reveal_type(idx)
reveal_type(val)
baz(idx, val)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8592.py | Python | from typing import TypeVar
from hypothesis import strategies as st
_Ex = TypeVar("_Ex", covariant=True)
def everything_except(*types: type) -> st.SearchStrategy[_Ex]:
strategy = st.from_type(type).flatmap(st.from_type)
return strategy.filter(lambda x: not isinstance(x, types)) # type: ignore
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8594.py | Python | from typing import TypeVar, Tuple, Optional
Result = TypeVar("Result")
WorkerResult = Tuple[
Optional[Result], # <- "No Anys on this line!"
Optional[BaseException], # <- "No Anys on this line!"
str # <- "No Anys on this line!"
]
WorkerResult = Tuple[Optional[Result], Option... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8601.py | Python | from decimal import Decimal
from typing import Union
def check(x: Decimal, y: Union[Decimal, int]) -> bool:
return x < -abs(y)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8603.py | Python | class A():
pass
class B():
def __init__(self):
self.a = A
b = B()
class C(b.a):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8604.py | Python | from typing import TypeVar
class Foo(object):
pass
FooOrStr = TypeVar('FooOrStr', Foo, str)
def doit(reset: bool, arg: FooOrStr) -> FooOrStr:
if reset:
if isinstance(arg, Foo):
reveal_type(arg)
arg = Foo()
elif isinstance(arg, str):
reveal_type(arg)
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8610.py | Python | from typing import ByteString
x: ByteString = b""
def foo(y: bytes) -> None:
pass
foo(x)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8619.py | Python | import operator
from functools import partialmethod
class IntCmp:
def __init__(self, value):
self._value = value
def _cmp(self, opr, other: int) -> bool:
if isinstance(other, int):
return opr(self._value, other)
return NotImplemented
__eq__ = partialmethod(_cmp, opera... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8622.py | Python | from typing import Tuple, Optional
a: Tuple[Optional[int], Optional[int]] = (1, 1)
b: Tuple[int, int]
if a[0] is not None and a[1] is not None:
b = a
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8623.py | Python | from typing import cast, Any
from typing_extensions import Protocol, runtime_checkable
import typeguard
class Foo():
@typeguard.typechecked
def __init__(self, x: int, y: int,z: int = 3):
self.x = x
self.y = y
self.z = z
print("init")
f = Foo(9,10)
print(f)
func = type(f).__init__
print("__init__... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8625.py | Python | from attr import attrs, attrib
from typing import FrozenSet, Text
@attrs
class Test(object):
values = attrib(type=FrozenSet[Text], converter=frozenset)
Test(values={'a'})
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8637.py | Python | def test() -> str:
c = None
for c in "":
pass
if c is None:
return None
return "foo"
print(test())
import typing
def test(l : typing.Sequence[str]) -> str:
c = None
for c in l:
pass
if c is None:
return None
return "foo"
print(test([]))
print(te... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8640.py | Python | gen = (3 * x for x in range(10)) # revealed type: Generator[int, None, None]
for i in gen:
print(i)
for i in gen:
print(i)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8647.py | Python |
from returns.pipeline import pipe
from returns.result import Result, Success, Failure, safe
from returns.pointfree import bind
def regular_function(arg: int) -> float:
return float(arg)
def returns_container(arg: float) -> Result[str, ValueError]:
if arg != 0:
return Success(str(arg))
return Failure(ValueE... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8655.py | Python | def test_launch_missile_only_accepts_str() -> None:
with pytest.raises(TypeError):
launch_missile(10) # error: Argument 1 to "launch_missile" has incompatible type "int"; expected "str" [arg-type]
launch_missile(10) # type: ignore[arg-type]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8656.py | Python | from typing import overload, List, Dict, Optional, Sequence, Union, Tuple
@overload
def f(a: List[Dict]) -> List[int]:
...
@overload
def f(a: List[Optional[Dict]]) -> List[Optional[int]]:
...
def f(
a: Union[List[Dict], List[Optional[Dict]]]
) -> Union[List[int], List[Optional[int]]]:
return [1]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8657.py | Python | import enum
from typing import Literal
class Color(enum.Enum):
BLACK = enum.auto()
BLACK = Color.BLACK
BLACK_ALIAS: Literal[Color.BLACK] = Color.BLACK
reveal_type(Color.BLACK)
reveal_type(BLACK)
reveal_type(BLACK_ALIAS)
import enum
from typing import Literal, Optional
class Color(enum.Enum):
BLACK = en... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8662.py | Python | TerminateHandlerContextType = TypedDict( "TerminateHandlerContextType",{...},)
CrashHandlerContextType = TypedDict( "CrashHandlerContextType", {... },)
QuitHandlerContextType = TypedDict("QuitHandlerContextType", {...})
TerminateHandlerType = Callable[[TerminateHandlerContextType], None]
QuitHandlerType = Callable[[Qu... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8663.py | Python | from typing import NamedTuple, Optional
class BaseInventory(NamedTuple):
number: Optional[int]
name: str
class Inventory(BaseInventory):
number: int
item = Inventory(42, 'parrot')
item.number % 10 # mypy allows this
number, _ = item
number % 10 # mypy does not allow this
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8666.py | Python | import itertools
itertools.starmap(
lambda x, y: True, filter(lambda in_deg: in_deg[1],
[(1, 2)]))
import itertools
import typing
itertools.starmap(
lambda x, y: True, typing.cast(typing.Iterable[typing.Tuple[int, int]],
filter(lambda in_deg: in_... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8670.py | Python | from sqlalchemy import Column, Integer
class Foo(Base):
oid = Column(Integer, primary_key=True)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8681.py | Python | from typing import Type, TypeVar, Tuple
T = TypeVar('T')
def func(a: T, a_type: Type[T]) -> Tuple[T, Type[T]]:
return a, a_type
a1, a1_type = func(1, int)
a2, a2_type = func(1, str)
reveal_type(a1)
reveal_type(a1_type)
reveal_type(a2)
reveal_type(a2_type)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8684.py | Python | import typing as t
constructor: t.Type[t.FrozenSet]
reveal_type(constructor)
constructor = frozenset
reveal_type(constructor)
constructor(range(10))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8695.py | Python | from typing import NamedTuple
class First(NamedTuple):
def method(self):
pass
class Second(NamedTuple):
recursive: 'Second'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8696.py | Python | from typing import Callable, Generic, Type, TypeVar
XType = TypeVar('XType', bound=int)
class C(Generic[XType]):
def f(self, x_init: XType) -> XType:
return x_init
def combinator(c_cls: Type[C[XType]]) -> Callable[[C[XType], XType], XType]:
old_f = c_cls.f
def new_f(c: C[XType], x_init: XType)... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8703.py | Python | from typing import List, Union
from dataclasses import dataclass, field
def foo():
@dataclass
class Foo:
foo: int
def __call__(self) -> asdf:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8704.py | Python | from typing import Optional
from typing import Sequence
from more_itertools import first
class A:
def some_method(self):
pass
def f(inp: Sequence[A]) -> Optional[A]:
return first(filter(lambda a: a.some_method(), inp), None)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8708.py | Python | from typing import Sequence, TypeVar, Union
D = TypeVar("D")
E = TypeVar("E")
def get_first(values: Sequence[E], default: D = None) -> Union[E, D]:
if len(values) == 0:
return default
else:
return values[0]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8714.py | Python | from mypy_extensions import TypedDict
class Grandparent(TypedDict):
a: str
class ParentB(Grandparent):
b: str
class ParentC(Grandparent):
c: str
class Child(ParentB, ParentC):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8715.py | Python | import math
import typing
Tuple = typing.Tuple
def cartesian(r: int, θ: int) -> Tuple[float, float]:
rad = math.radians(θ)
return r*math.cos(rad), r*math.sin(rad)
r = 12
θ = 195
x,y = cartesian(r, θ)
print(f"({r}, {θ}°) = ({x:.2f}, {y:.2f})")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8718.py | Python | from typing import Optional, Iterable, TypeVar, Callable
T = TypeVar('T')
def is_even(n: int) -> bool:
return n % 2 == 0
# equivalent to https://ruby-doc.org/core-2.5.0/Enumerable.html#method-i-detect
def detect(function: Callable[[T], bool],
iterable: Iterable[T]) -> Optional[T]:
for element in... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8721.py | Python | last = None
reveal_type(last) # Revealed type is 'None'
for val in range(10):
reveal_type(last) # Revealed type is 'None'
if last is not None and last < 2:
print("apparently unreachable")
reveal_type(last) # no output
reveal_type(last) # Revealed type is 'None'
last = val
reve... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8722.py | Python | class MyEnum(str, enum.Enum):
value: str
FIRST = 'first'
class MyEnum(enum.Enum[str]):
FIRST = 'first'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8723.py | Python | import unittest
class Tests(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.foo = 42 # "Type[Tests]" has no attribute "foo"
def test_foo(self) -> None:
print(self.foo) # "Tests" has no attribute "foo"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8734.py | Python | def foo() -> List[int]:
listings = None
if 2 != 2:
listings = list()
listings.append(1)
return listings
def foo() -> List[int]:
listings = None
if 2 != 2:
listings = [1]
return listings
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8737.py | Python | from typing import overload
class Example:
@overload
def fun(self, p: int) -> int: ...
@overload
def fun(self, p: str) -> str: ...
def fun(self, p=1):
if isinstance(p, int):
return 'foo'
else:
return 'bar'
prop = property(fun)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8746.py | Python | def now() -> str:
return "now"
def usage() -> None:
now = now()
print(now + "!")
usage()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8747.py | Python | foo = 0
foo = 1.0
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8754.py | Python | #!/usr/bin/env python3
from typing import (
Any,
Callable,
)
import requests
import tenacity
# Keep trying the request until we connect.
@tenacity.retry(retry=tenacity.retry_if_exception_type(requests.exceptions.ConnectionError))
def retry_if_connection_error(func: Callable[..., requests.Response], *args: Any, **k... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8759.py | Python | show_error_codes = True
disallow_any_explicit = True
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8760.py | Python | from typing import Any
def foo(**kwargs: Any) -> None: ...
foo(bar=reveal_type([1])) # Revealed type is List[Any]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8761.py | Python | from typing import Union, List, Literal, overload
class One:
pass
class Two:
pass
@overload
def func(x: Literal[False]) -> List[Two]:
...
@overload
def func(x: Literal[True]) -> List[Union[Two, One]]:
...
# actual definition typed with the most inclusive type
def func(x: bool) -> List[Union[Two, On... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8763.py | Python | from typing import AnyStr, Generic
class A(Generic[AnyStr]):
def __init__(self, arg: AnyStr):
# Case A... error: Need type annotation for 'attr'
self.attr = arg
reveal_type(arg)
# note: Revealed type is 'builtins.str*'
# note: Revealed type is 'builtins.bytes*'
re... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8764.py | Python | from typing import Union, Tuple
def func() -> Union[Tuple[None, None], Tuple[int, int]]:
...
a, b = func()
if a:
print(a + b)
if a is not None:
print(a + b)
# Unsupported operand types for + ("int" and "None")
# Right operand is of type "Optional[int]"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8766.py | Python | import contextlib
from typing import Iterator
@contextlib.contextmanager
def context_func() -> Iterator[None]:
try:
yield
except Exception:
pass
def foo() -> None:
with context_func():
raise Exception
print("xxx") # mypy: Statement is unreachable
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8769.py | Python | from typing import Any
class Hidden:
def __init__(self, z: float, **kwargs: Any):
super().__init__(**kwargs)
self.z = z
class Base:
def __init__(self, x: int, **kwargs: Any):
super().__init__(**kwargs)
self.x = x
class Inherited(Base):
def __init__(self, y: int, **kw... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8778.py | Python | class Foo:
@classmethod
def baz(cls):
return cls.__name__
class Bar(Foo):
pass
from typing import TypeVar
from .bar import Foo, Bar
FooType = TypeVar("FooType", bound=Foo)
def takes_foo(foo: FooType) -> FooType:
print(type(foo).baz())
return foo
class Foo2:
@classmethod
def ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8796.py | Python | from typing import Literal
class A:
foo : Literal['bar', 'spam']= 'bar'
class B(A):
foo = 'spam'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8800.py | Python | from typing import TypeVar, overload, Type, Optional, Generic
# Define a Player base class that can be paired with some data.
T = TypeVar('T')
class Player(Generic[T]):
pass
# Create an overloaded function to handle casting
# both Player and Optional[Player] to corresponding
# specific subtypes.
# (to ensure O... | 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.