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/10000-10999/10739.py
Python
from decimal import Decimal from typing import Union def f(elem: Union[int, str, Decimal]) -> None: if isinstance(elem, int): return for _ in range(3): if isinstance(elem, (Decimal, int)) and elem > 10: continue reveal_type(elem) return None from decimal import Decim...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10740.py
Python
from typing import Callable class Test: def method1(self) -> None: pass def method2(self, optional: int = 0) -> None: pass def test(self, something: bool) -> None: action: Callable[[], None] action = self.method1 if something else self.method2
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10747.py
Python
# For backwards compatibility python_version = 3.7 # Proposing adding this as an alternate option python_version = [3.7, 3.8, 3.9]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10749.py
Python
class X: def __init__(self, value: str | None = None, parent: X | None = None) -> None: if value is None: if parent is not None and parent.value is not None: value = "something" else: value = "something_else" reveal_type(value) self.val...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10752.py
Python
from typing import Any, Callable, overload @overload def foo(a: Callable) -> int: ... @overload def foo(a: Any) -> Any: ... def foo(a): pass a: str = foo(lambda x: x) from typing import Any, overload @overload def foo(a: int) -> int: ... @overload def foo(a: Any) -> Any: ... def foo(a): pass a: str = foo...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10755.py
Python
# test_case.py from numbers import Real from operator import floordiv, mul, truediv from typing import NamedTuple, Union _OperandT = Union[float, Real] # _OperandT = Real # <- results in the same error # _OperandT = float # <- this works class Spam(NamedTuple): value: _OperandT def __floordiv__(self, other...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10757.py
Python
import numpy as np def fun() -> None: np.save("path", [1, 2])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10763.py
Python
from typing import * import asyncio class Readable(Protocol): def read(self) -> bytes: pass class Seekable(Readable, Protocol): def seek(self, v: int) -> int: pass T_readable = TypeVar("T_readable", bound=Readable) T_seekable = TypeVar("T_seekable", bound=Seekable) class AsyncFile(...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10764.py
Python
from typing import Literal, Union from enum import Enum class ModelType(str, Enum): Simple1 = "simple1" Simple2 = "simple2" Complex1 = "complex1" Complex2 = "complex2" class BaseModel: type: ModelType class BaseSimpleModel(BaseModel): type: Literal[ModelType.Simple1, ModelType.Simple2] ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10765.py
Python
@given("I am on the main page") def step_impl(context): pass @when("I type login and password") def step_impl(context): pass @then("I am logged in") def step_impl(context): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10768.py
Python
def f(i: int = 0): i = "test" # This is a mypy violation. print(i) if __name__ == "__main__": f()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10773.py
Python
def foo(): if sys.platform != "win32": return 1 else: return 0 def foo(): if sys.platform != "win32": return 1 return 0
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10786.py
Python
# test_case.py from typing import Protocol, overload, runtime_checkable @runtime_checkable class PowableProto(Protocol): @overload def __pow__(self, other: "PowableProto") -> "PowableProto": ... @overload def __pow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": # <- f...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10790.py
Python
class A: def __init__(self) -> None: pass class B: def __init__(self, a: Optional[A]=None, b: Optional['B']=None) -> None: self.a=a self.b=b N = TypeVar('N') class PB(Protocol[N]): a: Optional[N] b: Optional['PB[N]'] def spam(b: PB[N], a: N): pass spam(B(), A())
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10799.py
Python
class Base: @overload def A(self, x: str) -> str: ... @overload def A(self, x: int) -> int: ... def A(self, x: Any) -> Union[str, int]: pass class Derived(Base): def A(self, x: Any) -> Union[str, int]: # Error here! pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10805.py
Python
def counter(func): def wrapper(*args, **kwargs): wrapper.count += 1 return func(*args, **kwargs) wrapper.count = 0 return wrapper @counter def greet(name: str) -> str: return f'hello, {name}' print(greet('John')) print(f'greet() called {greet.count} times') T = TypeVar('T', bound=Call...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10806.py
Python
a: object = None def foo() -> None: global a a = None bar() if a: print("hi") def bar() -> None: global a a = 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10817.py
Python
from typing import TypeVar class A: pass class B(A): pass QBT = TypeVar("QBT", bound=A) def fn(t: QBT) -> QBT: if not isinstance(t, B): raise NotImplementedError return t # <- Incompatible types in "return" (actual type "B", expected type "QBT") from typing import TypeVar, cast class A: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10820.py
Python
[tool.mypy] strict = true exclude = ".*epd.*" ignore_missing_imports = true allow_subclassing_any = true allow_untyped_calls = true
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10823.py
Python
from collections.abc import Set from dataclasses import dataclass @dataclass(order=True) class MySet(Set): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10826.py
Python
# sup/bro.py - This is the object we want to be available at the top level __all__ = ["Bro"] class Bro: pass # sup/__init__.py - This brings the Bro object to the sup module level from . import bro from .bro import * __all__ = bro.__all__ # __init__.py - This brings the sup module, including the Bro object, to ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10835.py
Python
from typing import TypeVar # context: T = TypeVar('T') class A: pass class B: pass def function1(obj: T) -> T: # expected behaviour: if isinstance(obj, A): pass elif isinstance(obj, B): pass return obj # no problem here def function2(obj: T) -> T: # unexpected behaviour: if isinst...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10847.py
Python
class Foo: bar = None
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10848.py
Python
from typing import Any import x # this will be of type Any as ignore-missing-imports is True class A(x): def __init__(self, *args, **kwargs): # type: (*Any, **Any) -> None self.a = 1 class B(A): pass class C(B): pass a = A() b = B() c = C() reveal_type(a) reveal_type(b) reveal_type(c) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10850.py
Python
# poc.py from dataclasses import dataclass from typing import Protocol, Final @dataclass class FinalY: y: Final[int] = 0 class Y(Protocol): y: int def f(x: Y) -> Y: x.y = 42 return x print(f(FinalY(17)))
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10851.py
Python
# Option A: Via helper from tickit.core.utils.compat.typing_compat import Protocol, runtime_checkable # Option B: Directly import sys if sys.version_info >= (3, 8): from typing import Protocol, runtime_checkable else: from typing_extensions import Protocol, runtime_checkable @runtime_checkable class Adapter(...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10854.py
Python
def doit(constructor: Callable[..., T]) -> List[T]: ... from typing import Callable, List, Protocol, TypeVar _T = TypeVar("_T") # error: Incompatible default for argument "constructor" (default has type "Type[str]", argument has type "Callable[[int], _T]") def generate(n: int, constructor: Callable[[int], _T] = ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10856.py
Python
... _a = make_fun('a') _b = make_fun('b') @overload def a(s: int) -> int: ... @overload def a(s: str) -> str: ... def a(s: T) -> T: return _a(s) @overload def b(s: int) -> int: ... @overload def b(s: str) -> str: ... def b(s: T) -> T: return _b(s)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10858.py
Python
from enum import Enum, unique @unique class A(Enum): x = 1 y = 1 def rand_int() -> int: ... @unique class A(Enum): x = rand_int() y = rand_int() z = 0
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10870.py
Python
class A: __slots__ = [] class A: __slots__ = () class A: __slots__ = [1, 2]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10872.py
Python
import typing_extensions as te x: te.Annotated[int, Foobar] = 42
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10874.py
Python
@dataclass class Range: start: object end: object def difference(self): return self.end - self.start a = Range(1, 2) from typing import * from dataclasses import dataclass T = TypeVar("T") class SupportsSub(Protocol[T]): def __sub__(self, other: T) -> T: ... RangeT = TypeVar("RangeT...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10878.py
Python
@overload def f(x: None, y: None) -> None:... @overload def f(x: str, y: int) -> int:... def f(x: Optional[str], y: Optional[int]) -> Optional[int]: if x is not None: return len(x) + y # error: Unsupported operand types for + ("int" and "None") else: return None class A: pass class B: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10890.py
Python
mapping: Dict[str, str] = {"a": "x"} val: Optional[str] = None val = "a" reveal_type(val) # Revealed type is "builtins.str" val = mapping[val] if val in mapping else val reveal_type(val) # Revealed type is "builtins.str" val = mapping.get(val, val) reveal_type(val) # Revealed type is "Union[builtins.str, None]"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10898.py
Python
from typing import final, Type, TypeVar, Union @final class A: def __init__(self, a: int) -> None: ... @final class B: def __init__(self, b: str) -> None: ... U = Union[A, B] T = TypeVar("T", A, B) def f(x: Type[U]) -> U: if issubclass(x, A): reveal_type(x) # Revealed typ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10910.py
Python
# test.py from enum import Enum class Food(Enum): SPAM = "spam" HAM = "ham" def is_spam(self) -> bool: return self is self.SPAM print(Food.SPAM.is_spam()) print(Food.HAM.is_spam()) def is_spam(self) -> bool: return self is Food.SPAM
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10911.py
Python
from typing import Union list1 = [1, 'b'] list2 = [2, 'd'] list3: list[Union[str, int]] = list1 + list2 dict1 = {1: 'a', 'b': 2} dict2 = {3: 'c', 'd': 4} dict3: dict[Union[str, int], Union[str, int]] = dict1 | dict2
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10915.py
Python
from typing import NoReturn, Literal from enum import auto, Enum def foo(value: Literal["foo","bar"]) -> None: if value == "foo": reveal_type(value) #note: Revealed type is "Literal['foo']" elif value != "bar": reveal_type(value) #error: Statement is unreachable [unreachable] class Foo(Enum):...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10943.py
Python
# test_cast.py from operator import __gt__, __lt__ from typing import Callable, TypeVar, Union _T = TypeVar("_T") def identity(__: _T) -> _T: return __ maybe_not_available_decorator = identity # <-- problematic decorator alias # try: # from spicy import spicy_decorator as maybe_not_available_decorator # ex...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10954.py
Python
# test_file.py from collections import namedtuple class Snapshot: def create_tuple_type(self, name: str): self.tuple_type = namedtuple(name, []) # line 6 def create_tuple_type_1(name: str): x = namedtuple(name, []) # line 9 def create_tuple_type_2(name: str): return namedtuple...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10957.py
Python
#!/usr/bin/env python3 import sys # test.py:9: error: Variable annotation syntax is only supported in Python 3.6 and greater def f() -> None: if sys.version_info <= (3,6): raise RuntimeError('python 3.6 or greater required') x: int = 0 print(x) # No mypy error def g() -> None...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10958.py
Python
class MyError(Exception): pass class RuntimeError(RuntimeError, MyError): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10962.py
Python
from typing import Type class Base: ... def get_base() -> Type[Base]: return Base BaseAlias: Type[Base] = get_base() class Derived(BaseAlias): ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10964.py
Python
from typing import Any, TYPE_CHECKING, overload class _IntDescriptorMeta(type): def __get__(self, instance: Any, owner: Any) -> int: return 123 class IntDescriptorClass(metaclass=_IntDescriptorMeta): ... class IntDescriptor: def __get__(self, instance: Any, owner: Any) -> int: return 123 ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10967.py
Python
import types from typing import List from .my_module import * __all__ = [] submodules: List[types.ModuleType] = [my_module] for submodule in submodules: __all__.extend(submodule.__all__) __all__ = ["my_var"] my_var = "hello!" from my_app import my_module print(my_module.my_var) from my_app.my_pkg import my_m...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10977.py
Python
m: Mapping[str, str] v: Union[str, bytes] if v in m: m[v]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10978.py
Python
from typing import Any, Mapping, MutableMapping def test_mutablemapping(obj: Mapping[Any, Any]) -> MutableMapping[Any, Any]: if issubclass(type(obj), MutableMapping): return obj # error: Incompatible types in assignment (expression has type "Mapping[Any, Any]", variable has type "MutableMapping[Any, Any]...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10986.py
Python
from dataclasses import dataclass from typing import Generic, List, TypeVar T = TypeVar('T', int, str) @dataclass class A(Generic[T]): x: List[T] @dataclass class B(A[int]): pass B(x=[1]) # error: List item 0 has incompatible type "int"; expected "T"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10990.py
Python
def export_file(src: str) -> str: with open(src) as f: data = f.read() return data
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10993.py
Python
f: int | str if isinstance(f, int): # error: Unsupported operand types for + ("str" and "int") # even though there's no chance the value could be a string here since the lambda is immediately invoked (lambda: f+1)() # no error, even though the lambda could get called later when the type changes as...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10997.py
Python
from typing import Any, Generator def foo() -> Generator[int, Any, None]: yield while True: yield 42
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10998.py
Python
from pathlib import Path import attr @attr.s class Options: path: Path = attr.ib(default='.', converter=Path)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/10000-10999/10999.py
Python
from typing import List, Union, Generic, TypeVar T = TypeVar("T") class Tree(Generic[T]): children: "List[Union[T, Tree[T]]]" def __init__(self, children: "List[Union[T, Tree[T]]]") -> None: self.children = children def all_sub_trees(self) -> None: sub_trees: "List[Tree[T]]" = [self] ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11001.py
Python
# simple function which the author doesn't realize can consume a single string # count_starts_lowercase("some string") should fail def count_starts_lowercase(x: Sequence[str]) -> int: return len([c for c in x if c[0] in string.ascii_lowercase]) # function with overloaded definitions based on str/Sequence[str] # th...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11003.py
Python
from typing import Literal def myfun(a: Literal["a", "b", "c"]) -> str: return a s = "a" myfun(s) def myfun2(a: Literal[1, 2]) -> int: return a b = 2 myfun2(b) c = 1 if s == "a" else 2 myfun2(c)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11004.py
Python
from typing import Any, Callable, Generic, overload, Optional, TypeVar, Tuple, Union Row = TypeVar("Row") class Connection(Generic[Row]): @overload def connect( self, *, row_factory: Callable[[], Row], **kwargs: Union[None, int, str] ) -> "Connection[Row]": ... @overload def conne...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11008.py
Python
class X: def __init__(self): self._foo = 123 def get_foo(self) -> int: return self._foo foo = property(get_foo) @foo.setter def foo(self, value: int) -> None: self._foo = value
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11013.py
Python
# test_case1.py from __future__ import annotations from typing import Protocol, runtime_checkable @runtime_checkable class Foo(Protocol): __slots__ = () def foo(self): ... class Bar: __slots__ = ("_t",) def __init__(self): self._t = True def foo(self): pass print(f"isinsta...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11024.py
Python
import pkg pkg.utils.bar1(pkg.foo1()) __all__ = ('foo1', 'foo2') from .module1 import foo1 from .module2 import foo2 def foo1() -> int: num = 1 return num from .utils import bar2 def foo2() -> str: num = 2 return bar2(num) def bar1(num: int) -> str: return 'a' def bar2(num: int) -> str: r...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11027.py
Python
def test(input): pass # type: ignore[assignment] def test(input): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11030.py
Python
def create_from_typeddict(d: Type[TypedDict]): ... _TD = TypeVar("_TD", bound=TypedDict) class Application(Generic[_TD]): state: _TD
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11031.py
Python
def get_π(): return 3
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11033.py
Python
global a # type: int global a a = 1 # type: int global a a = 1 # type: int
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11036.py
Python
from typing import Dict, Optional, Tuple import numpy as np class Meta(type): def __new__( cls, name: str, bases: Tuple[type, ...], dct: Dict, *args, a: Optional[int] = None, **kwargs ): return super().__new__(cls, name, bases, dct, *args, **kwargs) class A(np.ndarray, a=1, metaclass=M...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11037.py
Python
from typing import Callable, Generic, Optional, TypeVar, Union, overload F = TypeVar("F") G = TypeVar("G") class cache_readonly(Generic[F, G]): def __init__(self, func: Callable[[F], G]) -> None: self.func = func self.name = func.__name__ self.__doc__ = getattr(func, "__doc__", None) ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11039.py
Python
import enum class MyEnumMeta(enum.EnumMeta): def __getitem__(self, indexOrSlice): if isinstance(indexOrSlice, (int, slice)): return list(self)[indexOrSlice] else: return enum.EnumMeta.__getitem__(self, indexOrSlice) class MyEnum(enum.Enum, metaclass=MyEnumMeta): pass class Period(MyEnum): A =...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11040.py
Python
from abc import ABC, abstractmethod from typing import TypeVar, Iterable, Iterator T = TypeVar('T') class MyABC(ABC): @property @abstractmethod def items(self) -> Iterable[T]: ... def my_method(self) -> Iterator[T]: for item in self.items: yield item
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11046.py
Python
class DotDict(dict): __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ __getattr__ = dict.get
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11047.py
Python
# test.py from typing import NamedTuple ExampleClass = NamedTuple('ExampleClass', test_id=str, timestamp=str) ExampleClass = NamedTuple('ExampleClass', [(test_id, str), (timestamp, str)])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11049.py
Python
from typing import TypeVar T1 = TypeVar("T1") T2 = TypeVar("T2") def foo(a: T1, b: T2) -> T1 | T2: return a invalid = 1 if 1 else foo(1, "s") # error: Argument 2 to "foo" has incompatible type "str"; expected "int" valid = foo(1, "s") if 1 else 1
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11051.py
Python
from typing import Optional class Global: attr: Optional[int] = None G = Global() def f() -> None: G.attr = 1 def t() -> None: G.attr = None f() assert G.attr is not None reveal_type(G)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11056.py
Python
from dataclasses import dataclass class Event: def __init_subclass__(cls): dataclass(cls) class BaseEvent(Event): base_field: str class SubEvent(BaseEvent): sub_field: str SubEvent("base", "sub")
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11057.py
Python
class Base: def __init_subclass__(cls, keyword: int = 0): ... class Derived(Base, keyword='fail'): ... class Meta(type): ... class Base(metaclass=Meta): def __init_subclass__(cls, keyword: int = 0): ... class Derived(Base, keyword='fail'): ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11059.py
Python
def foo(): pass # type: ignore foo() # type: ignore[no-untyped-call]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11060.py
Python
x = 0 [x := x + y for y in range(2)] [z := z + y for y in range(2)] # ok for Python but error for mypy: Name "x" already defined x = 0 [x := x + y for y in range(2)] # ok for mypy, but Python error: NameError: name 'z' is not defined [z := z + y for y in range(2)]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11063.py
Python
from typing import TypeVar, Type, Generic, ClassVar, Any T = TypeVar("T", bound="Base[Any]") class Base(Generic[T]): instance_list: ClassVar[list[T]] @classmethod def init(cls: Type[T]) -> None: cls.instance_list = [] class Derived(Base["Derived"]): pass Derived.init() print(Derived.instance...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11065.py
Python
from multipledispatch import dispatch @dispatch(list, str) def concatenate(a: list, b: str): a.append(b) return a @dispatch(str, str) def concatenate(a: str, b: str): return a + b @dispatch(str, int) def concatenate(a: str, b: int): return a + str(b) @dispatch(int, str) def concatenate(a: int, b...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11071.py
Python
from typing import Callable, Union def some_func(obj: Union[Callable, int]): if isinstance(obj, Callable): reveal_type(obj) # Type of "obj" is "(*args: Unknown, **kwargs: Unknown) -> Unknown | int" else: reveal_type(obj) # Type of "obj" is "(*args: Unknown, **kwargs: Unknown) -> Unknown | int"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11076.py
Python
def ensure_correct_context(event: EventBase, context: EventContext): remote_auth_chain = get_event_auth(event) for auth_event in remote_auth_chain: # XXX: Problem is here! # We are introducing a bug because `context` which corresponds to `event` # is being re-assigned to the `context` for the `auth_even...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11086.py
Python
from typing import Union, overload from typing_extensions import Literal @overload def f(*, flag: Literal[True]) -> float: ... @overload def f(*, flag: Literal[False] = False) -> str: ... def f(*, flag: bool = False) -> Union[str, float]: return 5 reveal_type(f(flag=True)) reveal_type(f(flag=False)) reveal_type(f...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11090.py
Python
class OrmBase: pass class Orm1(OrmBase): pass class Orm1Prime(OrmBase): pass class Orm2(OrmBase): pass class Orm2Prime(OrmBase): pass def func(orm: Union[Orm1, Orm2]): orm_mapper = { Orm1: Orm1Prime, Orm2: Orm2Prime, } mapped: Union[Type[Orm1Prime], Type[Orm2Prime]]...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11093.py
Python
Block = dict[str, str] def main() -> Block: out = Block() # error: Need type annotation for "out" (hint: "out: Dict[<type>, <type>] = ...") return out if __name__ == "__main__": main()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11098.py
Python
a: type = tuple[int] # no error b = tuple[int] # no error c = tuple[int, int] # no error error: type = tuple[int, int] # error: Type application has too many types (1 expected) def foo(tp: type): ... foo(tuple[int, int])
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11100.py
Python
class Foo: pass class Outer: foo_class = Foo def foo_method(self): class FooInner(self.foo_class): pass class Foo: pass class Outer: foo_class = Foo def foo_method(self) -> None: class FooInner(self.foo_class): pass
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11101.py
Python
def foo(value: (T:=TypeVar("T"))) -> T: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11103.py
Python
# src/foo.py from mypy.api import run _, _, exit_code = run(["--install-types", "--non-interactive", "src"]) assert exit_code == 0
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11108.py
Python
class Spam(TypedDict): one: str x = Spam(one='one') Spam(**x)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11111.py
Python
from typing import TypeVar def handle_str(arg: str) -> str: return arg def handle_list(arg: list) -> list: return arg type_arg = TypeVar('type_arg', str, list[str]) def chooser__standard(arg: type_arg) -> type_arg: if isinstance(arg, str): return handle_str(arg) else: return hand...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11113.py
Python
from typing import TypeVar T = TypeVar("T", str, int) def hi(value: T) -> None: value.asdfasdf # error (qux := value.asdfasdf) # no error
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11117.py
Python
def deco(value) -> int: ... @deco class Class: ... reveal_type(Class) # note: Revealed type is "def () -> __main__.Class" @deco def function(): ... reveal_type(function) # note: Revealed type is "builtins.int"
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11118.py
Python
# cython: language_level=3 import cython from cython import double, size_t import numpy as np @cython.boundscheck(False) def func_with_mv(a: double[:]) -> np.ndarray: b: double[:] = np.empty_like(a) i: size_t for i in range(len(a)): b[i] = 2 * a[i] return np.asarray(b)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11142.py
Python
from typing import Literal class Some: def __init__(self) -> None: self.a = 1 s = Some() reveal_type(s.a) # Revealed type is "builtins.int" reveal_type(getattr(s, 'a')) # Revealed type is "Any" reveal_type(getattr(s, 'b')) # Revealed type is "Any" reveal_type(getattr(s, 'a', None)) # Revealed type is...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11149.py
Python
from typing import TypeVar, Union, List T1 = TypeVar("T1") def promote_list(item: Union[T1, List[T1]]) -> List[T1]: ... exprs: List[int] reveal_type(promote_list(exprs)) # error # ex.py:9: note: Revealed type is "builtins.list[<nothing>]" # ex.py:9: error: Argument 1 to "promote_list" has incompatible type "Lis...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11163.py
Python
from typing import TypeVar T = TypeVar('T') def function(arg: T) -> T: if isinstance(arg, type) and issubclass(arg, Exception): raise RuntimeError return arg # error: Incompatible return value type (got "Union[T, Type[object]]", expected "T") [return-value]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11164.py
Python
def func() -> bool: return True if not func: a: str = 4 reveal_type(a) else: b: str = 4 reveal_type(b) if func: c: str = 4 reveal_type(c) else: d: str = 4 reveal_type(d)
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11165.py
Python
from typing import ( Literal, overload, Sequence, TypeVar, Union, ) T1 = TypeVar('T1') T2 = TypeVar('T2') @overload def func(a1: Literal[True], a2: T1) -> Union[T1, Sequence[T2]]: ... # error: Overloaded function signatures 1 and 2 overlap with incompatible return t...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11167.py
Python
from typing import * CanCompare = TypeVar("CanCompare", bound='Comparable') class Comparable(Protocol): def __lt__(self: CanCompare, other: CanCompare) -> bool: pass def __gt__(self: CanCompare, other: CanCompare) -> bool: pass def __le__(self: CanCompare, other: CanCompare) -> bool: ...
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11188.py
Python
import tensorflow as tf def bar() -> tf.Tensor: return tf.zeros(0) def foo() -> str: return bar()
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11208.py
Python
from math import inf, nan from typing import Literal x: Literal[1.1] y: Literal[inf] z: Literal[nan]
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli
code_snippets/mypy/11000-11999/11211.py
Python
class A(object): @staticmethod def open(): return 123 @staticmethod def proccess(): return 456 switch = { 1: open.__func__, 2: proccess.__func__, }
Akuli/issue-downloader
0
Downloads code from GitHub issues and saves it to files
Python
Akuli