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/11000-11999/11678.py | Python | from typing import TypeVar
T = TypeVar('T')
class X:
def __init__(self: T):
super().__init__() # 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/11000-11999/11682.py | Python | a = ['a', 'bc']
b = map(list, a) # [['a'], ['b', 'c']]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11686.py | Python | class Parent:
# No error if there's no type hint in the constructor (type unimportant)
def __init__(self, args: int):
# The next line succeeds if it's a tuple, but fails on list.
self.var_a = []
# The type of this variable doesn't seem to matter at all, but it needs
# to exist an... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11689.py | Python | from typing import TypeVar
Self = TypeVar("Self")
class A:
def foo(self: Self) -> Self:
return self
class B(A):
def foo(self) -> B: # no error
return B()
class C(B):
a = 1
T = TypeVar("T", bound=A)
def foo(a: T) -> T:
return a.foo()
print(foo(C()).a) # run... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11691.py | Python | foo: dict[type, str] = {int: ""}
{**foo, str: ""}
# mypy seems to interpret it as this, where the error makes sense:
{str: ""}.update(foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11697.py | Python | from b import b
b: int = ""
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11710.py | Python | import sys
import foo
sys.modules["bar"] = sys.modules["foo"]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11715.py | Python | from enum import Enum
class E(Enum):
_order_ = 'X Y Z' # Should be 'X Y'
X = 1
Y = 2
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11720.py | Python | class Animal():
pass
class Bird(Animal):
def fly(self):
print("fly")
class Farm():
animal = Animal()
class FarmWithBirds(Farm):
animal = Bird() # why mypy is ok?
def func(f: Farm):
f.animal = Animal() # the magic
f = FarmWithBirds()
f.animal.fly() # print "fly"
func(f)
f.animal.fly() # ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11721.py | Python | from typing import NamedTuple
class NTup1(NamedTuple):
a: bool
class NTup2(NTup1): # Should be an error
b: bool
tup = NTup2(a=True, b=False) # Python: TypeError: <lambda>() got an unexpected keyword argument 'b'
# Mypy: error: Unexpected keyword argument "b" for "NTup2"
tup ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11723.py | Python | f"{None:%d/%m/%Y}" # runtime error
f"{'':1f}" # runtime error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11727.py | Python | @singledispatch
def foo(data: object) -> NoReturn:
raise ValueError(f"Unhandled type {type(data)}")
@foo.register
def _(data: str) -> str:
return data
@foo.register
def _(data: int) -> str:
return str(data)
a = foo(7)
reveal_type(a)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11728.py | Python | from typing import Generic, Any, TypeVar
import functools
T = TypeVar("T", bound="C")
@functools.total_ordering
class D(Generic[T]):
def __lt__(self, other: Any) -> bool:
...
class C:
pass
import functools
total_ordering = functools.total_ordering
@total_ordering
class D(Generic[T]): ...
if TYPE_... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11730.py | Python | from __future__ import annotations
from typing import Protocol, TypeVar
_T0 = TypeVar("_T0")
_T0_co = TypeVar("_T0_co", covariant=True)
_T1 = TypeVar("_T1")
_T1_co = TypeVar("_T1_co", covariant=True)
#%%
class FP0(Protocol[_T0, _T1]):
def __call__(self, arg0: _T0 | _T1, /) -> tuple[_T0, _T1]:
...
def ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11734.py | Python | from functools import singledispatch
@singledispatch
def f(x: object) -> int:
return 1
@f.register
def _(x: int, y: str) -> int:
return 2
print(f(1)) # No error reported, but fails at runtime
from functools import singledispatch
@singledispatch
def f(x: object, y: str) -> None:
y + ''
@f.register
def... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11745.py | Python | # main.py
from __future__ import annotations
from typing import Generic, Protocol, TypeVar
T = TypeVar("T")
U = TypeVar("U", bound=SupportsIAdd)
class SupportsIAdd(Protocol):
def __iadd__(self: T, other: T) -> T: ...
class AddingAccumulatorParam(Generic[U]):
def addInPlace(self, value1: U, ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11755.py | Python | from typing import List
if __name__ == "__main__":
x = List[str]([])
print(x)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11757.py | Python | from typing import Callable
def my_function(callback: Callable[...]) -> None:
callback()
from typing import Callable
def my_function(callback: Callable) -> None:
callback()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11762.py | Python | from typing import Literal, overload
class A:
def foo(self, bar: Literal["X"] | Literal["Y"]) -> int | bool:
if bar == "X":
return 1
else:
return True
class B(A):
@overload
def foo(self, bar: Literal["X"]) -> int:
...
@overload
def foo(self, bar: ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11764.py | Python | def foo(value: object | str) -> None:
if callable(value):
print(1) # Statement is unreachable [unreachable]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11765.py | Python | from typing import TypeGuard
def foo(value: TypeGuard[int]) -> None: ... # no error
bar: TypeGuard[int] = True # no error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11784.py | Python | from __future__ import annotations
import enum
class E(enum.Enum):
A = (1,)
B = (2,)
@property
def x(self) -> E:
reveal_type(type(self).__iter__)
reveal_type(iter(type(self)))
reveal_type(tuple(type(self)))
vals = tuple(type(self))
return vals[(vals.index(self... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11789.py | Python | # mypy: enable-error-code truthy-bool
class Foo:
pass
foo = Foo()
# Error: "foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context
if foo:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11791.py | Python | import typing as tp
import enum
@enum.unique
class ColorIndex(enum.IntEnum):
BLACK = 0
GREY = 1
WHITE = 2
def _missing_(cls, value: object) -> tp.Any:
return ColorIndex.BLACK
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11807.py | Python | funclist = [lambda x: print(1)]
funclist += [lambda k: print(2)] # incompatible signature, but type not widened and no error
reveal_type(funclist) # builtins.list[def (x: Any)]
funclist[1](x=4) # this will error at runtime because of a typing mistake
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11809.py | Python | class Foo:
def __init__(self, value:int) -> None:
self.value = value
class Bar(Foo):
def __init__(self) -> None:
pass
a = Bar().value # runtime error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11812.py | Python | from typing import Generic, TypeVar, TypedDict
class A(TypedDict):
a: str
T = TypeVar("T", bound=A)
class G(Generic[T]):
a: str
def foo(self, t: T) -> None:
t["a"] = "asd"
self.a = t["a"]
def bar(self) -> T:
return {"a": self.a}
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11834.py | Python | from typing import Dict, Any
def a(input:Dict[str, Any]) -> None:
pass
def b(input:Any=None) -> None:
a(input)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11835.py | Python | # t.py
class A:
def __new__(cls, *args, **kwargs) -> "B | C":
if cls is A:
cls = B
else:
cls = C
return object.__new__(cls)
class B(A):
pass
class C(A):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11836.py | Python | # t.py
from typing import Tuple, List
ElementT = Tuple[str, Tuple[str, List[str]]]
ContainerT = Tuple[ElementT, ...]
a: ContainerT = tuple((f1, (f2, [])) for f1, f2 in (("", ""), ("", "")))
b: ContainerT = (("", ("", [])),)
# The following four lines should be equally valid (or invalid) regarding types
# but only t... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11839.py | Python | from typing import Any
def func() -> Any:
...
var = func()
reveal_type(var) # Any
assert isinstance(var, bool)
reveal_type(var) # bool
if var:
reveal_type(var) # Literal[True]
pass
reveal_type(var) # Any -> should still be 'bool'!
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11840.py | Python | from typing import List, Sequence, TypedDict, Union
class TypeA(TypedDict):
fieldB: str
fieldC: bool
class _TypeB(TypedDict):
fieldA: str
fieldB: str
class TypeB(_TypeB, total=False):
fieldC: bool
ComponentT = Union[TypeA, TypeB]
ComponentListT = List[ComponentT] # Using List or Sequence causes... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11846.py | Python | from functools import partial
from typing import Callable, Generic, TypeVar
from typing_extensions import ParamSpec
R = TypeVar('R')
P = ParamSpec('P')
class custom_vjp(Generic[P, R]):
def __init__(self, fun: Callable[P, R], x: int = 0):
self.fun = fun
def __call__(self, *args: P.args, **kwargs: P.k... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11854.py | Python | from typing import TypeVar, Protocol
TValue = TypeVar('TValue', covariant=True)
# As an example, this does not give me any errors
class IValueProcessor(Protocol, Generic[TValue]):
...
from abc import ABC
from typing import Generic
from .value import TValue
class Service(ABC, Generic[TValue]): # Error occurs ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11855.py | Python | from typing import ParamSpec, Callable, TypeAlias
P = ParamSpec("P")
c: TypeAlias = Callable[P, int]
def f(n: c[P]) -> c[P]:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11871.py | Python | from typing import Self
class Widget:
def add_thing(self, value: str) -> Self:
self.value = value
return self
from typing import TypeVar
TWidget = TypeVar("TWidget", bound="Widget")
class Widget:
def add_thing(self: TWidget, value: str) -> TWidget:
self.value = value
return... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11875.py | Python | from functools import singledispatch
import typing as tp
@singledispatch
def f(x: tp.Any) -> None: pass
@f.register
def _f_list(x: list[int]) -> None: pass
if __name__ == '__main__':
f([1, 2, 3])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11876.py | Python | from typing import Union, NoReturn
def func() -> Union[str, NoReturn]:
return 'test'
func().lower()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11880.py | Python | from typing import Any, TypeVar, Union
T = TypeVar("T")
V = TypeVar("V", str, bytes)
def check_t(x: T | list[T]) -> T: ...
def check_v(x: V | list[V]) -> V: ...
x_str: str
x_list_any: list[Any]
x_str_list_any: str | list[Any]
# mypy does the correct thing here
reveal_type(check_t(x_str)) # str
reveal_type(check_t... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11884.py | Python | import typing
@typing.runtime_checkable
class Foo(typing.Protocol):
__slots__ = ()
class Bar:
pass
_T = typing.TypeVar("_T", bound="Foo")
def foo(f: _T) -> _T:
return f
print(issubclass(Bar, Foo))
print(isinstance(Bar(), Foo))
foo(Bar())
True
True
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11887.py | Python | import mmap
WriteableBuffer = mmap.mmap
ReadableBuffer = bytes | WriteableBuffer
import mmap
ReadableBuffer = bytes | mmap.mmap
from mmap import mmap
WriteableBuffer = mmap
ReadableBuffer = bytes | WriteableBuffer
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11888.py | Python | i: int = 1
s: str = 'hi'
i is s # error: Non-overlapping identity check (left operand type: "int", right operand type: "str")
if i is None: # ok
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11891.py | Python | class Bar(object):
...
reveal_type(Bar.__slots__)
reveal_type(Bar().__slots__)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11892.py | Python | class Response(StreamResponse):
_body: Optional[bytes]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11897.py | Python | from typing import Union
class A:
x: Union[int, str] = 5
class B(A):
x = 5
class C(B):
# error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
x = "5"
class RefA:
x: A
class RefB(RefA):
x = B()
class RefC(RefB):
# error: Incompati... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11900.py | Python | def foo() -> None:
user = None
while True:
if user is None:
user = 123
else:
print(1 + "lol")
foo()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11916.py | Python | import sys
if sys.version_info < (3, 8, 0):
import importlib_metadata as metadata
else:
from importlib import metadata
my_metadata = metadata.metadata("mypy") # just using mypy as an example here; could be any package's name
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11923.py | Python | from typing import List, Optional
from dataclasses import dataclass, field
@dataclass
class A:
x: Optional[List[int]] = field(default_factory=list)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11925.py | Python | from unknown import X
class A: ...
class B(X, A): ...
class C(B): ...
class D(C): ...
class E(D): ...
reveal_type(E() if bool() else D())
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11927.py | Python | from typing import overload
@overload
def foo(a: int) -> None: ...
@overload
def foo(a: str) -> None: ...
def foo(a: object) -> None: ...
def bar(a: int) -> None: ...
foo(b=1)
bar(b=1)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11928.py | Python | from typing import Generic, TypeVar, Iterable
T = TypeVar("T")
T1 = TypeVar("T1", bound=None)
class Test(Generic[T, T1]):
def test(self) -> None:
data1: list[T]
data2: list[T] | list[T1]
data3: list[T1] | list[T]
reveal_type(tester(data1)) # list[T]
reveal_type(te... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11929.py | Python | # error: Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "Union[List[int], List[str]]") [assignment]
foo: list[int] | list[str] = []
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11941.py | Python | # this works and does not throw an error
class A:
def __or__(self, v: int) -> A:...
def __ior__(self, v: int) -> None: ...
reveal_type(__or__) # note: Revealed type is "def (_error.A, builtins.int) -> _error.A"
reveal_type(__ior__) # note: Revealed type is "def (_error.A, builtins.int)"
# this er... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11947.py | Python | from typing import Optional
class Node: ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11949.py | Python | class Application(MutableMapping[Union[str, AppKey[Any]], Any]):
@overload
def __getitem__(self, key: AppKey[_T]) -> _T: ...
@overload
def __getitem__(self, key: str) -> Any: ...
def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
return self._state[key]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11953.py | Python | from typing import overload, Callable
@overload
def bar() -> None: ...
@overload
def bar(fn: Callable[[int], object]) -> None: ...
def bar(fn: object=1) -> None: ...
bar(lambda value: reveal_type(value))
bar(lambda value: reveal_locals())
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11956.py | Python | a: int
b = 1
if isinstance(a, bool):
reveal_locals() # "b: int", I would expect "a: bool, b: int"
reveal_type(a) # "a: bool" ✔
def foo(a: int) -> None:
b: int
reveal_locals() # "a: int, b: int", this is correct, but inconsistent with top level
reveal_type(a)
a: int = 1
reveal_locals() # not... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11958.py | Python | from typing import cast
foo: str
a = cast(int, foo)
a = cast(int, cast(object, foo))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11959.py | Python | from typing import Any
foo: Any #type:ignore[misc]
foo # no error
print(foo) # error: Expression has type "Any"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11964.py | Python | from __future__ import annotations
import os
from pathlib import Path
def _calc_usage(target_path: Path | os.DirEntry) -> None:
with os.scandir(target_path) as scanner:
for entry in scanner:
if entry.is_dir():
_calc_usage(target_path)
else:
print('f... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11967.py | Python | def func(item: int) -> None:
print(item)
if True:
item = "amogus"
else:
item = "amogus"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11968.py | Python | list[int] is list[str]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11969.py | Python | from dataclasses import dataclass
@dataclass
class Foo:
value: int
modified: bool = False
def update(self) -> None:
self.value += 1
self.modified = True
foo = Foo(42)
assert not foo.modified
foo.update()
assert foo.modified
print("Reached")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11970.py | Python | import enum
from dataclasses import dataclass
from typing import TypeVar, Generic, Type
M = TypeVar('M', bound="MyEnum")
class Meta(enum.EnumMeta):
pass
class MyEnum(metaclass=Meta):
...
class Foo(enum.Enum, MyEnum):
item1 = "1"
item2 = "2"
class Bar(enum.Enum, MyEnum):
item1 = "1"
item2 ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11976.py | Python | foo: list[str]
if isinstance(foo, list):
reveal_type(foo) # note: Revealed type is "list[str]"
else:
# error: Unused "type: ignore" comment
# note: Revealed type is "<nothing>"
reveal_type(foo) #type:ignore[unreachable]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11979.py | Python | from typing import Optional, Final
def example_func(value: Optional[int] = None):
condition: Final = value is not None
if condition:
reveal_type(value) # Revealed type is "Union[builtins.int, None]"
value = value + 1 # MYPY ERROR
if value is not None:
reveal_type(value) # Re... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11985.py | Python | #!/usr/bin/env python3
from collections.abc import Iterable
from typing import Optional
import os
def min_direntry_good(
fs: 'Iterable[os.DirEntry[str]]'
) -> 'Optional[os.DirEntry[str]]':
r = min(fs, default=None, key=lambda x: x.stat().st_mtime)
return r
def min_direntry_bad(
fs: 'Iterable[... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11988.py | Python | class A(TypedDict):
a: str
class BC(TypedDict, total=False):
other: str
a: str
Spec = Union[A, BC]
class Config(TypedDict):
prop: Spec
def main_prop(build: Spec) -> None:
reveal_type(build)
print(build)
def main_config(config: Config) -> None:
reveal_type(config["prop"])
print(confi... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11990.py | Python | _SUPPORTED_LITERAL_OPERATIONS: Final = {
int: ('+', '-', '*', '//'), # `/` returns `float`
str: ('+',),
bool: ('and', 'or'),
}
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11993.py | Python | T = TypeVar('T')
class MyClass(Generic[T]):
def meth_1(self, x: T) -> T: ...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11994.py | Python | from typing import List
class SampleClass:
an_attribute: int
foo: List[SampleClass] = []
bar = map(lambda an_instance: an_instance.an_attribute, foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/11000-11999/11995.py | Python | from typing import Union, NewType
Int = NewType("Int", int)
Float = NewType("Float", float)
def raw_types(arg: Union[int, float, None]) -> None:
if isinstance(arg, int):
reveal_type(arg) # Revealed type is "builtins.int"
elif isinstance(arg, float):
reveal_type(arg) # Revealed type is "built... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12001.py | Python | from copy import deepcopy
from typing import Literal, Union
def f(a: str, b: bool) -> Union[Literal[True], str]:
return b or deepcopy(a)
print(f("abc", False))
print(f("abc", True))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12005.py | Python | from typing import TypeAlias, Union
class Dog:
pass
class Cat:
pass
class Salmon:
pass
class Trout:
pass
Mammal: TypeAlias = Dog | Cat
Fish: TypeAlias = Salmon | Trout
Animal: TypeAlias = Mammal | Fish # type error!!
Animal2: TypeAlias = Union[Mammal, Fish] # no type error, as expected
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12006.py | Python | from typing import Final
foo: Final[int | None] = 1
if foo is not None:
def bar() -> None:
reveal_type(foo) # note: Revealed type is "Union[builtins.int, None]"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12009.py | Python | class A: pass
class B: pass
class C:
attr: A | B | None
c = C()
if c.attr is None: pass
elif isinstance(c.attr, A): pass
elif isinstance(c.attr, B): pass # Optional line - no difference if removed
reveal_type(c.attr)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12011.py | Python | import typing as t
TCallable = t.TypeVar("TCallable", bound=t.Callable[..., t.Any])
P = t.ParamSpec("P")
class X(t.Generic[TCallable]):
pass
class Y(t.Generic[P], X[t.Callable[P, t.Any]]): # error: The first argument to Callable must be a list of types or "..."
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12012.py | Python | k = AppKey("k", int)
app[k] = "foo"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12013.py | Python | from typing import Callable, Generator
class Parent:
def method_without(self) -> "Parent":
...
def method_with(self, param: str) -> "Parent":
...
class Child(Parent):
method_without: Callable[["Child"], "Child"]
method_with: Callable[["Child", str], "Child"]
no_implicit_optional = ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12015.py | Python | foo: object
if isinstance(foo, list):
a = foo[1]
reveal_type(a) # Any
a.asdfasdfasdf # no error
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12016.py | Python | from typing import overload
@overload
def foo(a: int) -> int: ...
# this overload was just removed
# @overload
# def foo(a: None) -> str ...
@overload
def foo(a: str) -> str: ...
def foo(a: object) -> object: ...
a = foo(None) # error: No overload variant of "foo" matches argument type "None"\
# error: Expressio... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12036.py | Python | from typing import Optional, Union, Text
def ensure_unicode1(t: Optional[Union[str, Text]]) -> Optional[Text]:
if t is None:
return None
elif isinstance(t, bytes):
return t.decode('utf-8')
return t
def ensure_unicode2(t: Optional[Union[str, Text]]) -> Optional[Text]:
if t is None:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12045.py | Python | class Book(models.Model):
author = models.ForeignKey(Author, null=True)
# related_field_minimal.pyi
from typing import Generic, Literal, Optional, Type, TypeVar, overload
class Model: ...
_M = TypeVar("_M", bound=Optional[Model])
class ForeignKey(Generic[_M]):
@overload
def __new__(
cls,
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12046.py | Python | from dataclasses import dataclass, InitVar
@dataclass
class MyClass:
prop: InitVar[int]
_prop: int
def __post_init__(self, prop: int):
self._prop = prop
@property
def prop(self) -> int:
return self._prop
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12049.py | Python | def foo(x: object) -> TypeGuard[Any]:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12059.py | Python | from typing import cast
def foo(a: object) -> None:
cast(int, a)
print(a + 1)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12060.py | Python | from typing import TypeVar
T = TypeVar("T")
def foo(t: type[T], data: str) -> None:
if isinstance(data, t):
print(data.__str__) # error: <nothing> has no attribute "__str__"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12061.py | Python | from typing import Annotated, ClassVar, Final
class C:
classvar: Annotated[ClassVar[int], (2, 5)] = 4
const: Annotated[Final[int], "metadata"] = 4
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12076.py | Python | # type: ignore[no-untyped-def]
def untyped(): pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12082.py | Python | def foo() -> bool:
return None == None
class Thing:
thing: str | None
def something(self, that: Thing) -> bool:
if self.thing is not None or that.thing is not None:
return True
else:
return self.thing == that.thing # no error, despite None == None
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12084.py | Python | from dataclasses import dataclass
from typing import Any, Callable
# here both `Parent` and `Child` are frozen dataclasses
@dataclass(frozen=True)
class Parent:
__call__: Callable[..., None]
def __call__(self, *args: Any, **kwargs: Any) -> None: # type: ignore
raise NotImplementedError
@dataclass(... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12089.py | Python | reveal_type(asyncio.gather(*[asyncio.sleep(1), asyncio.sleep(1)]))
reveal_type(asyncio.gather(*[reveal_type(asyncio.sleep(1)), asyncio.sleep(1)]))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12092.py | Python | def return_a(strings: list[str]) -> Optional[str]:
# Item "None" of "Optional[str]" has no attribute "strip"
return next(filter(lambda s: s.strip() == "a", strings), None)
def matches_a(s: str) -> bool:
return s.strip() == "a"
def return_a(strings: list[str]) -> Optional[str]:
# Argument 1 to "filter"... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12098.py | Python | class _SessionData(TypedDict):
created: int
session: Dict[str, Any]
class _EmptyDict(TypedDict):
"""Empty dict for typing."""
SessionData = Union[_SessionData, _EmptyDict]
data: SessionData
reveal_type(data)
a = data if data else None
reveal_type(a)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12101.py | Python | from typing import Generic, TypeVar
from tjax._src.fixed_point.base import IteratedFunctionBase
State = TypeVar('State')
Parameters = TypeVar('Parameters')
Trajectory = TypeVar('Trajectory')
class SimpleScan(IteratedFunctionBase[Parameters, State, Trajectory, State],
Generic[Parameters, State, Traje... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12103.py | Python | # test_case.py
from __future__ import annotations
from functools import wraps
from typing import Callable, Optional, Protocol, TypeVar, Union, overload
_ReturnsIntT = Callable[..., int]
_SubjectT = TypeVar("_SubjectT", bound=_ReturnsIntT)
class _DecoratedT(Protocol):
def __call__(self, *args: int, join_str="", **... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12107.py | Python | from enum import (
auto,
Enum,
)
class Game(Enum):
TENNIS = auto()
PING_PONG = auto()
SOCCER = auto()
def is_racquet_sport(self) -> bool:
return self in {self.TENNIS, self.PING_PONG}
# error: Non-overlapping container check (
# ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12108.py | Python | [tool.mypy]
# SEE: http://mypy.readthedocs.io/en/latest/config_file.html#config-file
# Specifies the Python version used to parse and check the target program.
python_version = 3.10
# Enables PEP 420 style namespace packages.
namespace_packages = true
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12109.py | Python | from typing import Iterable
from enum import Enum
from tests.imported import STRING
class E(Enum):
a = STRING
b = None
@classmethod
def keys(cls) -> Iterable[str]:
return (key.name for key in cls if key.value is not None)
print(list(E.keys()))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/12000-12999/12112.py | Python | from typing import cast, Dict, Generic, Type, TypeVar
def make_mixin(key: str):
T = TypeVar('T', bound="Mixin")
# T represents an instance of a Mixin subclass.
class Mixin(Generic[T]):
KEY: str = key
def to_str(self) -> str:
return "a string"
@classmethod
de... | 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.