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/6000-6999/6898.py
Python
from typing import TypeVar, Union T = TypeVar("T") def get_or_str(value: T) -> Union[str, T]: return value def f(b: bool) -> Union[str, bool]: return "" if b else get_or_str(True)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6910.py
Python
from dataclasses import dataclass, fields @dataclass class Foo: value: str fields(Foo)[0].default_factory
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6933.py
Python
from typing import * T = TypeVar('T') InT = TypeVar('InT') OutT = TypeVar('OutT') class Transform(Generic[InT, OutT]): "Takes an input Collection and produces an output Collection" def __init__(self, fn: Callable[[InT], OutT]): self.fn = fn def call(self, arg: InT) -> OutT: return self....
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6936.py
Python
from typing import cast, Generic, Optional, TypeVar, Union from whereever import MustUse T = TypeVar("T") E = TypeVar("E") # We inherit from MustUse to ensure this type isn't ignore class Result(Generic[T, E], MustUse): def __init__(self, value: Union[T, E], is_ok: bool): self._value = value self....
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6963.py
Python
x = None # type: List[int] ... # Do nothing with `x` x = [] # Want to preserve type context
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6967.py
Python
from typing import Type class Foo: def __init__(self, a): self.a = a class Bar(Foo): def __init__(self): super().__init__("Bar") def takes_foo(foo: Type[Foo]): x = foo("Foo") takes_foo(Foo) takes_foo(Bar)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6968.py
Python
o = [[1, 2], ["foo", "bar"]] reveal_type(o) [len(x) for x in o]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6976.py
Python
from typing import List def foo() -> None: global bar bar = [] # type: List[str] # Name 'bar' already defined (possibly by an import) bar # Name 'bar' is not defined
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6978.py
Python
class A: x: str def x(self) -> str: ... class B: x: int def x(self) -> int: ... class C(A, B): ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/6000-6999/6992.py
Python
from typing import overload, Tuple @overload def foo(a: int, c: bool = True) -> int: ... @overload def foo(a: int, b: int, *args: int, c: bool = True) -> Tuple[int, ...]: ... def foo(a, *args, c=True): if len(args) == 0: return a return (a,) + args if __name__ == '__main__': print(foo(1)) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7006.py
Python
# test.py import foo_mod import foo_mod.bar_mod as bar_mod class baz(foo_mod.foo, bar_mod.bar): pass # foo_mod/__init__.py class foo: pass # foo_mod/bar_mod.py class bar: pass # out/test.pyi # Stubs for test (Python 3) # # NOTE: This dynamically typed stub was automatically generated by stubgen. import...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7008.py
Python
from typing import * class Foo: def __bool__(self) -> Literal[True]: return True def some_foo() -> Foo: ... def throw_error(): raise Exception if __name__ == '__main__': print(some_foo() or throw_error()) # ^^^^^^^^^^^^^ impossible condition, unreachable
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7012.py
Python
class Foo: pass reveal_type(Foo.__name__)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7015.py
Python
from typing_extensions import final class Base: @final def __init__(self): pass class A(Base): def __init__(self): # no error raised pass class B(Base): def __init__(self) -> None: # raises an error pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7038.py
Python
import asyncio from typing import Type, TypeVar import aiohttp ResponseType = TypeVar("ResponseType", str, bytes) # ResponseType = TypeVar("ResponseType") <- This works, but it's not what I need in real life async def post(response_type: Type[ResponseType]) -> None: async with aiohttp.ClientSession() as session:...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7084.py
Python
from typing import TypeVar, Dict T = TypeVar('T') Alias = Dict[str, T] x: Alias[T] reveal_type(x) # Revealed type is 'builtins.dict[builtins.str, T?]'
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7109.py
Python
from typing import Callable, Optional class Base: formatter1: Callable[[int], str] formatter2: Optional[Callable[[int], str]] formatter3: Optional[Callable[[int], str]] formatter4: Optional[Callable[[int], str]] class Sub(Base): @staticmethod def formatter1(value: int) -> str: return s...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7121.py
Python
import typing class Base: A: typing.Type[Base] class One(Base): class A(Base): # overrides Base.A pass class Two(Base): class A(One): # overrides Base.A pass T = typing.TypeVar('T', bound=Base) class Foo(typing.Generic[T]): # the generic def foo(self, a: typing.Ty...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7187.py
Python
from typing import Callable, Union, Tuple def f(x: Union[Callable[..., int], Callable[..., str]]) -> None: ... x: Callable[..., Union[int, str]] f(x) def g(y: Union[Tuple[int], Tuple[str]]) -> None: ... y: Tuple[Union[int, str]] g(y)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7192.py
Python
assert isinstance(email, EmailMessage) # Fine r1 = email.get("List-Id", "") # Fine r2 = email.get("List-Id", "") or email.get("List-Unsubscribe", "") # Fine r3 = bool(email.get("List-Id", "") or email.get("List-Unsubscribe", "")) # FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool" r4...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7203.py
Python
from os import makedirs makedirs('src/core') makedirs('src/stuff') open('src/__init__.py', 'w').write(""" # nothing here """) open('src/core/__init__.py', 'w').write(""" from .run import config """) open('src/core/run.py', 'w').write(""" from ..stuff import somefunction config = None somefunction() """) open('sr...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7204.py
Python
import sys from typing import Optional found_id = None symbols_list = [{'symbol': 'A', 'id': 1}, {'symbol': 'B', 'id': 2}, {'symbol': 'B', 'id': 3}] for entry in symbols_list: if entry['symbol'] == 'B': if found_id: print('error, symbol found multiple times!') sys.exit(1) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7206.py
Python
def func(x: int) -> int: return x + 1 def func(x): return x def func(x): return x def func(x: int) -> int: return x + 1 from test import func def func(x: int) -> int: return x + 1 def func(x: int) -> int: return x + 1 from test import func def func(x): return x
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7217.py
Python
from collections import defaultdict from typing import DefaultDict from mypy_extensions import TypedDict RepoPath = str RepoStatus = TypedDict('RepoStatus', { 'branch': str, 'remote': str, 'clean': bool, # ... }, total=False) State2 = defaultdict(RepoStatus) # type: DefaultDict[RepoPath, R...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7224.py
Python
from typing import Protocol, Generic, TypeVar, NamedTuple, List, Any class Example(Protocol): sentence: List[str] T = TypeVar('T', bound=Example) class Dataset(Generic[T]): ... class ConcreteExample(NamedTuple): sentence: List[str] others: Any class ConcreteDataset(Dataset[ConcreteExample]): .....
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7248.py
Python
# coding: utf-8 # mypy: warn_return_any # mypy: disallow_any_expr # mypy: disallow_any_generics from typing import Sequence def getStringSequence(value:object) -> Sequence[str]: if isinstance(value, Sequence): reveal_type(value) # Revealed type is Sequence[Any] return value raise TypeError
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7249.py
Python
from typing import Optional def the_method(maybe_int: Optional[int]): can_divide = bool(maybe_int) if can_divide: 100 / maybe_int
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7252.py
Python
x: Union[int, str] = 0 # type of x is Union[int, str] here! x: Union[int, str] x = 0 # type of x is int here!
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7255.py
Python
from mypy_extensions import TypedDict from typing import TypeVar, Generic, Type T = TypeVar('T') class G(Generic[T]): def __init__(self, x : Type[T]): self.x = x D = TypedDict('D', {}) def f(x: G[D]): pass f(G(D))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7311.py
Python
from typing import * T1 = TypeVar('T1') T2 = TypeVar('T2') T_contra = TypeVar('T_contra', contravariant=True) T_co = TypeVar('T_co', covariant=True) class Callback(Protocol[T_contra, T_co]): def __call__(self, __element: T_contra) -> T_co: pass def applyit(func: Callback[T1, T2], y: T1) -> T2: return func...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7336.py
Python
class ParentA: def get_description(self, s: str): ... class ParentB: def get_description(self, i: int): ... # This is a Liskov violation and needs to be ignored. class ParentViolation(ParentA, ParentB): # type: ignore ... class ShouldBeIrrelevant: ... # Inheriting from a violating parent, showi...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7338.py
Python
from typing import overload, Optional, List @overload def f(x: int) -> List[int]: ... @overload def f(x: None) -> List[Optional[int]]: ... def f(x: Optional[int]) -> List[Optional[int]]: return [x]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7339.py
Python
from typing import Any, Dict, Optional def rename_keys( original_dict: Dict[str, Any], key_mapping: Dict[str, Optional[str]] ) -> Dict[str, Any]: """Renames keys in the dictionary using the key_mapping. If the value in key_mapping is None then it will remove the key entirely""" return { key_mappin...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7356.py
Python
import sys try: f = open('.', 'rb') except PermissionError if sys.platform == "win32" else (): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7362.py
Python
import typing T = typing.TypeVar('T', str, int) class Base(typing.Generic[T]): def __init__(self, bar: T): self.bar: T = bar class Child(Base[T]): def __init__(self, bar: T): super().__init__(bar)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7391.py
Python
from contextlib import AbstractContextManager from typing import TYPE_CHECKING, Optional, Type from types import TracebackType if TYPE_CHECKING: _Base = AbstractContextManager['A'] # problematic "line 6" else: _Base = AbstractContextManager class A(_Base): def __enter__(self) -> 'A': return self ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7394.py
Python
class A: attr = None class B(A): attr: str # type: ignore class C1(B): attr = "test" class C2(B): pass class D(C2): attr = "test"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7402.py
Python
from typing import Union class Foo: def __mod__(self, other: Union[Foo, str]) -> Foo: ... def __rmod__(self, other: str) -> Foo: ... from typing import Union class Foo: def __mul__(self, other: Union[Foo, str]) -> Foo: ... def __rmul__(self, other: str) -> Foo: ... from typing import Union class Fo...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7408.py
Python
def f(a: int) -> None: pass x = [1, 2] f(*x) # Currently accepted, since mypy doesn't know the length of x x = [1, 2] a, b, c = x # Currently accepted def f(a: int, b: int) -> None: pass def g(x: List[int]) -> None: assert len(x) == 2 f(x[0], x[1])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7422.py
Python
from typing import Tuple, Union def x() -> Union[Tuple[int, int], Tuple[str, str]]: ... a, b = x() if isinstance(b, int): reveal_type(a) # can only be int but is reported as Union[int, str]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7432.py
Python
x: bytes y = str(x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7435.py
Python
from typing_extensions import Literal, TypedDict from typing import Optional class Super: type: str class Foo(Super): type: Literal['foo'] class SuperDict(TypedDict): type: str class Bar(SuperDict): type: Literal['bar'] class SuperTuple(NamedTuple): type: str class Baz(SuperTuple): type: L...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7456.py
Python
from typing import List class Upi(object): pass class Subi(Upi): pass subs = [Subi(), Subi()] ok1:List[Upi] = [s for s in subs] ok2:List[Upi] = list(subs) notOk:List[Upi] = subs[:] # this should also be ok IMHO
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7464.py
Python
from typing import Any, Callable, Type, TypeVar, Union, cast _T = TypeVar("_T") class Cls: ... def wrap(decorator: Callable[[_T], _T]) -> Callable[[_T], _T]: ... s: Callable[[_T], _T] w = wrap(s) s(Cls) w(Cls) # error: Argument 1 has incompatible type "Type[Cls]"; expected "_T" reveal_type(s) reveal_type(w)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7468.py
Python
from typing import Generic, TypeVar, TYPE_CHECKING L = TypeVar('L') R = TypeVar('R') if TYPE_CHECKING: # type declarations class Either(Generic[L, R]): pass Left = Either[L, None] Right = Either[None, R] else: # runtime implementation class Either(): pass class Left(Either): pass class Ri...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7472.py
Python
def deco(x): return x @deco # Error: Name 'bad' is not defined def f(y): # type: (bad) -> None pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7479.py
Python
'{:.3f}'.format(sum(list_of_floats))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7494.py
Python
some_var = 1 @my_decorator(some_var) def my_func(x): return x
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7509.py
Python
from typing import List, Tuple def get_point_as_list() -> List[int]: return [1, 2] def point_to_tuple(pt: List[int]) -> Tuple[int, int]: assert len(pt) == 2 return tuple(pt) if __name__ == "__main__": l = get_point_as_list() p = point_to_tuple(l) print(repr(p))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7511.py
Python
import typing def no_return_optional(arg) -> typing.Optional[str]: if arg: return "false" def no_return(arg) -> str: if arg: return "false" a1 = no_return_optional(True) a2 = no_return_optional(False) reveal_type(a1) reveal_type(a2) b1 = no_return(True) b2 = no_return(False) reveal_type(b...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7533.py
Python
from typing import Set, FrozenSet, List, Tuple from typing_extensions import Literal T = Literal[1, 2, 3] l: List[T] = [1, 2] t1: Tuple[T, ...] = (1, 2) t2: Tuple[T, T] = (1, 2) s1: Set[T] = {1, 2} s2: Set[T] = set([1, 2]) s3: Set[int] = set((1, 2)) f1: FrozenSet[T] = frozenset([1, 2]) f2: FrozenSet[int] = frozenset((...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7534.py
Python
('', '', 2)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7542.py
Python
f: Any class MyClass: def __init__(*args, **kwargs) -> None: ... @classmethod def run(self, unicodeaction: str) -> None: ... def __reduce__() -> Any: ... def __setstate__(state) -> Any: ... def is_c_function(obj: object) -> bool: return inspect.isbuiltin(obj) or type(obj) is type(ord)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7556.py
Python
Base = some.custom_class('Base', ...) class Model(Base): ... class Model(some.custom_class('Base', ...)): # the hook is not called here ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7563.py
Python
from enum import Enum class Responses(str, Enum): NORMAL = 'something' TEMPLATED = 'insert {value} here' Responses.TEMPLATED.format(value=42)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7568.py
Python
from enum import Enum class EnumClass(Enum): one = 1 EnumAlias = EnumClass EnumAlias['one']
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7595.py
Python
class X: def __new__(cls) -> "X": return super(type, cls).__new__(cls) # error: Argument 2 for "super" not an instance of argument 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7600.py
Python
def make_upper(i): args = [a.upper() for a in i] if isinstance(i, set): return set(args) else: return args T = TypeVar("T", List[str], Set[str]) def make_upper(i: T) -> T: args = [a.upper() for a in i] if isinstance(i, set): return set(args) else: retu...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7602.py
Python
import collections class Q: z = collections.namedtuple('z', ['hi', 'there'])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7616.py
Python
from typing import Iterable, Iterator, Union from typing_extensions import Protocol class MixedIter(Protocol): def __iter__(self) -> Iterator[Union[int, str]]: ... def f(xs: Iterable[Union[int, str]]) -> str: return ''.join(str(x) for x in xs) def g(xs: MixedIter) -> str: return ''.join(str(x) for x in x...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7626.py
Python
from typing_extensions import Protocol, Literal class Char(Protocol): def __len__(self) -> Literal[1]: ... a: Char = "X"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7711.py
Python
from .document import load_document import mdl doc = mdl.load_document( "happy" )
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7721.py
Python
# example.py def f1(*args): pass def f2(*args): return f1(*args) # this is the problem statement # example.py def f1(*args) -> None: pass def f2(*args): return f1(*args)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7726.py
Python
from contextlib import ExitStack def context_manager_with_return_bug() -> int: with ExitStack() as stack: return 5
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7752.py
Python
from typing_extensions import Literal, TypedDict class TDict(TypedDict): KEY1: int KEY2: int d1: TDict = {'KEY1': 1, 'KEY2': 2} key2: Literal['KEY1'] d2: TDict = {key2: 1, 'KEY2': 2} key3: Literal['KEY1', 'KEY2'] d3: TDict = {key3: 1, 'KEY2': 2} # error: Expected TypedDict key to be string literal
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7758.py
Python
def idiv(left: int, right: int | right != 0) -> int: return left // right
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7777.py
Python
from foo import bar
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7781.py
Python
from typing import overload class Snafu(object): @overload @staticmethod def snafu(value: None) -> None: ... @overload @staticmethod def snafu(value: bytes) -> bytes: ... @overload @staticmethod def snafu(value: str) -> bytes: ... @staticmethod def snafu(value): r...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7814.py
Python
from typing import Dict from typing_extensions import Literal T = Literal[1, 2, 3] d: Dict[T, None] d = {x: None for x in [1, 2, 3]} # error: Key expression in dictionary comprehension has incompatible type "int"; expected type "Union[Literal[1], Literal[2], Literal[3]]" d = dict(zip([1, 2, 3], [None, None, None])) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7835.py
Python
from typing import Dict from dataclasses import dataclass @dataclass class Foo: bar: bool @dataclass class Bar: baz: bool foo_registry: Dict[str, Foo] = {} bar_registry: Dict[str, Bar] = {} use_foo = True registry = foo_registry if use_foo else bar_registry registry.get('asdfsdf')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7853.py
Python
from typing import List class A: pass class B(A): pass def test(arg: List[A]) -> None: if all([isinstance(a, B) for a in arg]): test2(arg) def test2(arg: List[B]) -> None: pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7856.py
Python
from typing import Any, Union, Optional from typing_extensions import Literal from mypy_extensions import TypedDict class Test(TypedDict): a: str b: int c: int TestKeys = Literal["a", "b", "c"] # QUESTION: is there a Test.KEYS or something equivalent? TestValue = Union[str, int] # QUESTION: is there a...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7858.py
Python
from typing import Iterable from typing import List from typing import MutableSequence from typing import Union from typing import overload class RecordBehaviourList(MutableSequence[str]): def __init__(self, lst: List[str]) -> None: self._lst = lst @overload def __getitem__(self, index: int) -> s...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7861.py
Python
from typing import TypeVar, Generic T = TypeVar('T') class Base(Generic[T]): def __init__(self, item: T) -> None: self.item = item def foo(self) -> None: pass class Sub(Base[T]): def foo(self: Sub[str]) -> None: self.item + 'no' # This is why the above is unsafe. a: Base[int] = S...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7864.py
Python
from typing import Callable, Iterable, TypeVar A = TypeVar("A") B = TypeVar("B") def identity(x: A) -> A: return x # ok def _map(queue: Iterable[B], function: Callable[[B], A]) -> Iterable[A]: return map(function, queue) # fails def _map2(queue: Iterable[B], function: Callable[[B], A] = identity) -> Iterabl...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7884.py
Python
from __future__ import annotations from typing import * class B: pass class A: name: Optional[Union[str, B]] def foo(a: A): if isinstance(a.name, str): pass elif isinstance(a.name, B): pass else: raise AssertionError bar(a.name) def bar(arg: Union[str, B]): ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7893.py
Python
def extract_commit_hash(line): # type: (str) -> Optional[str] ... def extract_commit_hash2(line): # type: (str) -> Optional(str) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7894.py
Python
class Foo: num: int = 1 msg: str = "hello" FooProtocol = protocol(Foo, include_private=False) FooLookalike = NamedTuple("FooLookalike", [("num", int), ("msg", str)]) # ok maybe_foo: FooProtocol = FooLookalike(num=2, msg="bye") # ok maybe_foo = Foo() # safely cast when using Fakes in a test test_foo(cast(Foo, m...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7905.py
Python
from typing_extensions import Literal, TypedDict from enum import Enum class Key(Enum): X = 1 Y = 2 Z = 3 class MyDict(TypedDict): key: Literal[Key.X, Key.Y] blah: int KEY: Literal["key"] = "key" d: MyDict if d["key"] is Key.X: reveal_type(d["key"]) # note: Revealed type is 'Literal[Key.X]...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7912.py
Python
import attr @attr.s class Bar: b = attr.ib() @classmethod def make(cls, one: int) -> 'Bar': return cls(one) @attr.s class Foo: a = attr.ib(converter=Bar.make)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7913.py
Python
from typing import MutableSet, Sequence, TypeVar T = TypeVar('T', str, Sequence[str]) class CustomSet(MutableSet[T]): def add(self, value: T) -> None: pass foo = CustomSet() foo.add(('a', 'b'))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7928.py
Python
from typing import Optional def my_func() -> bool: return True created: bool = my_func() a: Optional[int] = None if created: a = 1 z = a + 1 # This is OK if created: x = a + 1 # Unsupported operand types for + ("None" and "int")
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7935.py
Python
from typing import TypeVar, Generic, overload T = TypeVar('T') class C(Generic[T]): @overload def __new__(cls) -> C[None]: ... @overload def __new__(cls, item: T) -> C[T]: ... def __new__(cls, item=None): ... @classmethod def f(cls, x: T) -> T: return x C.f(42) # Argument...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7945.py
Python
class meta (type): pass class value (metaclass=meta): pass class submeta (meta): @property def attr(cls) -> int: return 42 class subvalue (metaclass=submeta): @property def attr(self) -> int: return 21 o = subvalue() a = o.attr print(a) a = subvalue.attr print(a)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7981.py
Python
from typing_extensions import final, TypedDict @final class Point(TypedDict): x: float y: float z: float p: Point x: str reveal_type(p.values()) reveal_type(p.items()) reveal_type(p.get(x, 0.0))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7984.py
Python
# mypy: allow-redefinition def f() -> None: x = 0 print(x) x = 'x' def g() -> None: reveal_type(x) # int, but should be str
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/7000-7999/7998.py
Python
[mypy-package.lib.uitls] disallow_any_generics = True
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8005.py
Python
from typing import Protocol class P(Protocol): def foo(self) -> int: ... class A(P): # mypy does not flag this pass class B: pass test: P = A() # mypy does not flag this test = B() # mypy flags this print(A().foo() + 5) # both error at runtime print(B().foo() + 5)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8029.py
Python
# mypy: no-implicit-optional def add(self, a: int, b: int = None) -> int: return a + b
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8043.py
Python
a = defaultdict(list) a[0].append('yes') b = {} b.setdefault(0, []).append('yes') c = defaultdict(set) c[0].add('yes') d = {} d.setdefault(0, set()).add('yes')
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8057.py
Python
from typing import Type class Foo: def __set_name__(self, owner: Type['Bar'], name: str) -> None: ... class Bar: foo_bar = Foo() # correctly passes class Baz: foo_baz = Foo() # should fail
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8113.py
Python
map(list, [{1}])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8117.py
Python
from typing import Generic, Iterable, Iterator, Sequence, TypeVar _T = TypeVar('_T') class Windowed(Generic[_T]): def __init__(self, it: Iterable[_T], size: int) -> None: self.it = it self.size = size def __iter__(self) -> Iterator[Sequence[_T]]: iters = tee(self.it, self.size) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8129.py
Python
from typing import Callable, NoReturn, TypeVar def no_return() -> NoReturn: pass def use_decorated_before_defined() -> int: decorated() if bool(): return 0 else: no_return() T = TypeVar('T') def wrapper(function: T) -> T: return function def decorator() -> Callable[[T], T]:...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8130.py
Python
class Outer(Base): field: Outer.Inner # E: Name 'Outer.Inner' is not defined class Inner: pass class Base: pass # inner class before its use class Outer(Base): class Inner: pass field: Outer.Inner class Base: pass # base before its use class Base: pass class Outer(Base): field: Outer.Inner class Inner: p...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8178.py
Python
from typing import NamedTuple class Example(NamedTuple): a: int = 1 b: int = 2 c: int = a*b d: int = does_not_exist*5 from typing import NamedTuple class Example(NamedTuple): a: int = 1 b: int = 2 # c: int = a*b d: int = does_not_exist*5
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8182.py
Python
x = [] for s in 'x', 'y': if 1 in x: # No error, but should be x.append(s)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8191.py
Python
from typing import * T_co = TypeVar('T_co', covariant=True) class Col(Generic[T_co]): def __init__(self, items: Iterable[T_co]) -> None: self.items = items def any(self, pred: Callable[[T_co], bool]) -> bool: return any(map(pred, self.items)) def any_zero(self, fn: Callable[[T_co], int]) -> bool: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8203.py
Python
from typing import Literal LiteralStrHello = Literal["hello"] LiteralStrWorld = Literal["world"] class A: def __getattr__(self, name: LiteralStrHello) -> LiteralStrWorld: assert name == "hello" return "world" def __getattribute__(self, name: LiteralStrHello) -> LiteralStrWorld: asser...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/8000-8999/8206.py
Python
class A: pass from imp import * a=A()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli