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/9000-9999/9335.py | Python | from typing import TypedDict
class Base(TypedDict):
id: int
class Derived(Base, total=False):
description: str
update_me: Derived = {
'id': 1,
'description': 'norsetanrst'
}
new_data: Derived = {
'id': 2
}
# "incompatible type" error from mypy
update_me.update(new_data)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9346.py | Python | def a():
pass
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
def a():
pass
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
def a(... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9354.py | Python | from typing import Sequence
import attr
@attr.s
class A:
a: Sequence[str] = attr.ib(converter=list)
A(["a"])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9356.py | Python | def get_mock_module(v: Literal["mock"] | Literal["unittest.mock"]) -> ...:
return pkgutils.resolve_name(v)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9357.py | Python | from typing import Callable, Generic, NamedTuple, Optional, Protocol, TypeVar
GenericType = TypeVar("GenericType")
class ClassOne(Protocol[GenericType]):
def function(self, _: GenericType) -> Optional[GenericType]:
return None
class ClassTwo(NamedTuple, Generic[GenericType]):
not_: Callable[[Class... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9369.py | Python |
from typing import (
Dict,
Optional,
)
def check1(x: Optional[str]) -> str:
assert x # x: str
return x # x: str
def check2(x: Optional[str]) -> str:
assert x # x: str
x_map: Dict[str, str] = {
"x": "y"
}
x = x_map.get(x, x) # x: Optional[str] ??
return x # x: Optional[str] ??
def check3(x: Option... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9372.py | Python | from functools import cmp_to_key
x = [(1, '')]
def f(): pass
reveal_type(cmp_to_key)
x.sort(key=cmp_to_key(lambda x, y: f())) # Cannot infer type argument 1 of "cmp_to_key"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9373.py | Python |
S = TypeVar('S', bound='Spec')
from __future__ import annotations
from typing import TypeVar, Type, overload, Generic
S = TypeVar("S", bound='Spec')
class Spec:
def __init__(self, name):
self.name = name
@overload
def __get__(self: S, obj: None, typ: Type[Service[S]]) -> S: ...
@overload
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9385.py | Python | from typing import List, AnyStr
from glob import glob
import itertools as it
def expand_patterns(
pats: List[AnyStr],
sort=True
):
paths = it.chain(map(glob, pats))
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Calla... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9393.py | Python | from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9397.py | Python | from __future__ import annotations
from typing import NamedTuple, Optional
class A(NamedTuple):
a: Optional[A]
from __future__ import annotations
from typing import Optional
from dataclasses import dataclass
@dataclass(frozen=True)
class A:
a: Optional[A]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9408.py | Python | from typing import TypedDict
class Value(TypedDict):
key1: str
key2: str
const1: Value = {"key1": "foo", "key2": "bar"}
const2: Value = {**const1, "key2": "eggs"}
# ^^^^^^^^
# mypy: Expected TypedDict key to be string literal (10:20)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9409.py | Python | from dataclasses import dataclass
from typing import Literal
@dataclass
class Data:
state: Literal["on", "off"]
def set_state(self, state: Literal["on", "off"]):
self.state = state
def test_func():
obj = Data("on")
assert obj.state == "on"
obj.set_state("off")
# ^^^^^^^^^^^^^^^^ ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9413.py | Python | def foo(): # implicit None
print("hi")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9416.py | Python | from typing import Optional
from typing import overload
from typing import Type
class A:
pass
class Field:
def __init__(self, attr: Optional["Field"] = None):
self.attr = attr
@property
def crashing_property(self) -> Optional["Field"]:
return self.attr
@overload
def __get__(s... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9420.py | Python | from typing import TypeVar, overload, Type, Tuple, Union
class Foo:
pass
class Bar:
pass
T1 = TypeVar('T1', bound=Foo)
T2 = TypeVar('T2', bound=Bar)
@overload
def f(cls: Type[T1]) -> Tuple[T1]:
pass
@overload
def f(cls: Type[T2]) -> Tuple[T2]:
pass
def f(cls: Union[
Type[T1],
Type[T... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9423.py | Python | from typing import Any, Callable, List, Mapping, Tuple, TypeVar
U = TypeVar('U', bound=Mapping[str, Any])
def f(dict_factory: Callable[[List[Tuple[str, Any]]], U] = dict) -> U:
return dict_factory([('a', 1)])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9424.py | Python | from typing import Optional, TypeVar
U = TypeVar('U', bound=Optional[int])
def f(u: U) -> U:
if u is None:
return None
assert isinstance(u, int) # removing this line causes it to pass.
return u
from typing import Optional, TypeVar, overload
@overload
def f(u: None) -> None: ...
@overload
def... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9427.py | Python | from decimal import Decimal
from collections import OrderedDict
GRID = OrderedDict(sorted({
(93, 659): Decimal('0.3000'), (93, 714): Decimal('0.2950'), (93, 749): Decimal('0.2820'), (93, 799): Decimal('0.2690'), (93, 850): Decimal('0.1990'), # noqa: E501
(94, 659): Decimal('0.3000'), (94, 714): Decimal('0.290... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9430.py | Python | from typing import Dict
a: Dict[str, str] = {"x": "y"}
b: Dict[str, str] = {"y": "z"}
def f(x: str) -> str:
f_a = a.get(x)
reveal_type(f_a) # Optional[str]
f_b = b.get(f_a, "default") # error: Argument 1 to "get" of "Mapping" has incompatible type "Optional[str]"; expected "str"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9431.py | Python | from __future__ import annotations
from typing import Callable, Generic, Iterable, Iterator, Optional, Protocol, TypeVar, runtime_checkable
TValue = TypeVar('TValue')
@runtime_checkable
class PNode(Protocol):
parent: Optional[PNode]
def parents(self) -> Iterator[PNode]: ...
class Node(Generic[TValue]):
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9433.py | Python | from common import encoder
import simplejson as json
class MyJSONEncoder(json.JSONEncoder):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # type: ignore
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9434.py | Python | class AttributeDict(Dict[str, Any]):
# Mypy is failing to realise that self is dict here.
__setattr__ = dict.__setitem__ # type: ignore[assignment]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9435.py | Python | from typing import List, TypeVar, Union
_T = TypeVar("_T")
def func(param: Union[List[_T], List[List[_T]]]) -> _T:
...
func([1])
func([[1]])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9436.py | Python | from typing import Protocol, TypeVar, Generic
# Define a protocol for `__radd__`
T_co = TypeVar("T_co", covariant=True)
T_contra = TypeVar("T_contra", contravariant=True)
class SupportsRAdd(Protocol[T_contra, T_co]):
def __radd__(self, other: T_contra) -> T_co: ...
class generic: ... # baseclass for numpy scala... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9442.py | Python | [mypy-pytest-asyncio]
disallow_untyped_decorators = false
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9447.py | Python | class Base:
def a(self, a: int) -> None: ...
class Derived(Base):
def a(self, _a: int) -> None: ...
def foo(b: Base) -> None:
b.a(a=1)
foo(Derived())
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9455.py | Python | from typing import *
S = TypeVar("S")
T = TypeVar("T")
def map_or_else(func: Callable[[S], T], value: Optional[S], default: T) -> T:
if value is None:
return default
return func(value)
# No mypy error
def func_1():
data: Dict[str, List[str]] = {
"items": [
"a", "b", "c",
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9457.py | Python | class Foo:
def __init__(self) -> None:
self.dirty = False
def test_source() -> None:
foo = Foo()
def bar() -> None:
foo.dirty = True
assert foo.dirty is False
bar()
assert foo.dirty is True
print("unreachable?")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9464.py | Python | from typing import Protocol, overload, TypeVar
# Step 1: Define the class
class ndarray:
@overload
def argmax(self, axis: None) -> int: ...
@overload
def argmax(self, axis: int) -> ndarray: ...
# Step 2: Define a Protocol for describing the classes' argmax method
T_contra = TypeVar("T_contra", contra... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9482.py | Python | # THIS VERSION WORKS, BUT REQUIRES MODIFYING CODE WITH EXTRA CLASS
from typing import TypeVar, Generic, List, Union, overload
from typing_extensions import Protocol
from datetime import datetime
T = TypeVar("T", covariant=True)
S = TypeVar("S")
class datetime64(int):
"""Stand-in for np.datetime64."""
class Inde... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9484.py | Python | stringy = "foo"
f"""\
{stringy.nope()}
""" # type: ignore
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9491.py | Python | from typing import Generic, TypeVar
T = TypeVar("T", bound="A", covariant=True)
class A(Generic[T]):
...
class B(A["B"]):
...
class C(A["C"]):
...
def f(x: A[T], y: A[T]) -> A[T]:
return x
b = B()
c = C()
res_typed: A = f(b, c) # OK
res_typed2: A[A] = f(b, c) # OK
res_untyped = f(b, c) # mypy error... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9496.py | Python | from typing import Callable, TypeVar
Fn = TypeVar("Fn", bound=Callable[..., object])
def foo(fn: Fn) -> Fn: # type safe usage
fn(1) # not type safe usage
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9524.py | Python | val = 1337
if val is not None:
pass
if val is not None and True:
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9527.py | Python | def identity(x: int) -> int:
return x
def double(x: int) -> int:
return x * 2
def add(x: int, y: int) -> int:
return x + y
calls_same_signatures = (
(identity, (1,)),
(double, (2,)),
)
calls_different_signatures = (
(identity, (1,)),
(add, (1, 2)),
)
for f1, args1 in calls_same_signatur... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9541.py | Python | from typing import Optional
def func(x: Optional[int]) -> int:
if isinstance(x, type(None)):
return 0
else:
return x + 1 # This is line 7
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9545.py | Python | def f(a=5) -> None:
a="ads"
def g() -> None:
f("asd")
class A:
a=5
A.a = "asd"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9560.py | Python | # pep249.py
from typing import Any
from typing_extensions import Protocol, runtime_checkable
@runtime_checkable
class Connection(Protocol):
def close(self) -> None: ...
def commit(self) -> None: ...
def rollback(self) -> None: ...
def cursor(self, *__args: Any, **__kwargs: Any) -> Any: ...
# main.py
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9565.py | Python | class A: ...
class B(A):
x: int
class C(A):
x: int
o: object
assert isinstance(o, (B, C))
_ = o.x
if isinstance(o, B):
...
elif isinstance(o, C):
...
else:
raise AssertionError("unreachable")
_ = o.x
o: object
assert isinstance(o, (B, C))
o: Union[B, C]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9569.py | Python | from typing import TypeVar, List, Type
TypeArgT = TypeVar("TypeArgT", Type, List[Type])
def type_a(*args: TypeArgT):
...
def type_b(*args: List[Type]):
...
type_a(int, str, float) # test t1
type_a([str, float], [int]) # test t2 <-- this does not work
type_b([bool, bool],... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9578.py | Python | from typing import List, TypeVar
import attr
_Foo = TypeVar('_Foo', bound='Foo') # comment this line and the problem goes away
@attr.s
class Foo:
_type = List[str]
bar = attr.ib(type=_type)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9579.py | Python | x = None
y = min(x, 11) if x is not None else 10
x = None
if x is not None:
y = min(x, 11)
else:
y = 10
x = None
y = min(x, 11) if x is not None else 10
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9585.py | Python | from dataclasses import dataclass
from typing import TypeVar, Generic, Dict, Any
T = TypeVar("T")
class FloatValue:
pass
@dataclass
class ValueByKey(Generic[T]):
values: Dict[Any, T]
def foo(v: ValueByKey[FloatValue]):
reveal_type(v.values)
reveal_type(ValueByKey[FloatValue].__init__)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9597.py | Python | from typing import Dict, Type
from typing_extensions import Protocol
class HasName(Protocol):
name: str
class Class1(HasName):
name = 'class1'
def __init__(self, a: int):
pass
class Class2(HasName):
name = 'class2'
def __init__(self, a: int, b: int):
pass
class Class3(HasNa... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9600.py | Python | from typing import Callable, TypeVar
T = TypeVar("T")
x = 1
def decorate(num: int) -> Callable[[T], T]:
def thru(it: T) -> T:
print("decorating", it, "with", num)
return it
return thru
class y(object):
@decorate(x)
def a(self) -> None:
...
x = 2
@decorate(x)
d... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9603.py | Python | # -*- coding: utf-8 -*-
from typing import Any, Dict, Optional
class Base(object):
"""Base class to demonstrate issue."""
def func(self, *args, **kwargs) :
"""Do nothing."""
reveal_type(self.func) # note: Revealed type is 'def (*args: Any, **kwargs: Any) -> Any'
class Derived1(Base):
def ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9612.py | Python | from typing_extensions import final
class Base(object):
"""Can be sub-classed."""
@final
class Child(Base):
"""Final instance."""
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9618.py | Python | from typing import final
class Base:
@final
def foo(self):
pass
def bar(self):
pass
class Derived(Base):
def foo(self):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9619.py | Python | from jaraco import text
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9627.py | Python | MyUnion = strawberry.union("Entity", types=(str, int))
MyUnion = Union[str, int]
from __future__ import annotations
import strawberry
x: MyUnion
MyUnion = strawberry.union("Entity", types=(str, int))
reveal_type(MyUnion)
reveal_type(x)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9643.py | Python | import io
class MyStringIO(io.StringIO):
def readline(self, size=None) -> str:
return super().readline(size)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9644.py | Python | class TestObject(object):
__slots__ = ["a", "b"]
a: int
b: str
def __init__(self, a: int, b: str) -> None:
self.a = a
self.b = b
def test() -> None:
x = TestObject(5, "hi")
reveal_type(TestObject.a)
reveal_type(TestObject.b)
reveal_type(x.a)
reveal_type(x.b)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9645.py | Python | from typing import Dict, TYPE_CHECKING, Tuple, cast
class Field:
pass
class FieldBuilder:
def with_name(self) -> 'FieldBuilder':
return self
# Imagine arbitrarily more builder methods
def build(self) -> Field:
return Field()
class BaseMeta(type):
def __new__(mcs, name: str, b... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9646.py | Python | FOO = "foo"
import constants
def bar():
# type: () -> str
print("{foo}".format(foo=constants.FOO))
return "{constants.FOO}".format(constants=constants)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9650.py | Python | Foo = Literal["foo"]
Bar = NewType("Bar", str)
Baz = NewType("Baz", Foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9654.py | Python | import typing as T
V = T.TypeVar("V")
V2 = T.TypeVar("V2")
def apply(val: V, func: T.Callable[[V], V2]) -> V2:
return func(val)
xs = []
apply(0, lambda a: xs.append(a))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9656.py | Python | from typing import Any
x: Any = [1, 2, 3]
sorted([0, 2, 1], key=lambda i: x[i])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9658.py | Python | def example_1(p1: Optional[int]):
if p1 is not None:
late_p1 = (lambda: p1)
reveal_type(late_p1)
def example_2(p1: Optional[int]):
if p1 is not None:
late_p1: Callable[[], int] = (lambda: p1)
reveal_type(late_p1)
def example_3(p1: Optional[int]):
if p1 is not None:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9666.py | Python | class SubModel(BaseModel):
entries: list
class MyModel(BaseModel):
myessentialfield: str
myoptionalfield: Optional[SubModel] = Field(alias="whatever",default=None)
@app.get("/")
def hello() -> MyModel:
responseA = MyModel(myessentialfield="foo")
responseA.myoptionalfield = SubModel(entries=[]) #... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9668.py | Python | from typing import Any, Awaitable, Callable, Protocol, Union, TypeVar, Generic
class IRequest:
pass
KleinSynchronousRenderable = Union[str, bytes]
KleinRenderable = Union[
KleinSynchronousRenderable, Awaitable[KleinSynchronousRenderable]
]
T_co = TypeVar('T_co', contravariant=True)
class KleinRoute(Proto... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9676.py | Python | import datetime
datetime.timedelta(**{"seconds": 1.0})
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9689.py | Python | from typing import Callable
def mydeco(f: Callable) -> Callable:
return f
# Failing case
def something():
class Query:
@mydeco
def search(self, input: str) -> str:
return input
reveal_type(Query.search)
# Failing case
def something():
@mydeco
def example() -> str:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9690.py | Python | from typing import TypeVar
class Foo:
pass
class Bar(Foo):
pass
T = TypeVar('T', bound=Foo)
class Program:
def get_foo_ish(self) -> T:
...
@property
def foo_ish(self) -> T:
...
program = Program()
bar1: Bar = program.get_foo_ish()
bar2: Bar = program.foo_ish # error: Incompatible types... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9706.py | Python | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: fenc=utf-8:et:ts=4:sts=4:sw=4:fdm=marker
from typing import Optional, Sequence, Mapping
import collections
class ModuleInfo:
def __init__(
self,
name: str,
version_attributes: Sequence[str],
min_version: Optional[str] = None
)... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9709.py | Python | class C:
def __init__(self, a: str) -> None:
if a is None:
self.x = 123
else:
self.x = 456
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9710.py | Python | from typing import Tuple
def x(x: int, y: int) -> None:
print(x, y)
def foo1(t: tuple) -> None:
x(*t[:1], 1)
def foo2(t: tuple) -> None:
x(*t[:2])
def foo3(t: Tuple[int]) -> None:
x(*t[:1], 1)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9718.py | Python | from typing import Literal
a: Literal[1, 2, 3] = 2
assert a in (1, 2)
b: Literal[1, 2] = a
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9726.py | Python | import copyreg
print(copyreg.__cached__)
OUTPUT = '''\
/usr/lib/python3.8/__pycache__/copyreg.cpython-38.pyc
'''
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9731.py | Python |
import typing as t
def spam(val: t.Union[t.Type, None] = None) -> None:
def eggs(type_: t.Type) -> None:
pass
reveal_type(val)
if isinstance(val, type):
reveal_type(val)
val, foo = None, val
reveal_type(val)
reveal_type(foo)
return eggs(foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9743.py | Python | from typing import (
Generic,
TypeVar,
)
_MyType = TypeVar("_MyType", str, float)
class MyGeneric(Generic[_MyType]):
def __init__(self, attr: int) -> None:
ls = [0]
self.attr = attr # mypy says: error: Need type annotation for 'attr'
if (a := sum(ls)): # mypy says: error: ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9745.py | Python | from typing import List
def average(numbers: List[float]) -> float:
"""Return the average of a non-empty list of numbers."""
return sum(numbers) / len(numbers)
from typing import List, NonEmpty
def average(numbers: NonEmpty[List[float]]) -> float:
"""Return the average of a non-empty list of numbers.""... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9765.py | Python | x = list(map(sorted, [[1, 3, 2], [2, 5, 4, 0]]))
assert x == [[1, 2, 3], [0, 2, 4, 5]]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9770.py | Python | from attr import attrs, attrib
@attrs(frozen=True)
class Name:
name: str = attrib(converter=str.lower)
def __str__(self) -> str:
return self.name
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9773.py | Python | # Returns `value` if it conforms to the specified type annotation using typechecker subtyping rules.
def trycast(typelike: TypeForm[T], value: object) -> Optional[T]: ...
# Returns whether the specified value can be assigned to a variable with the specified type annotation using typechecker subtyping rules.
def isassi... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9776.py | Python | import mock
import typing
class Foo:
def bar(self, a: int) -> str:
return str(a)
# I want to pass a spec'd mock here (mock.create_autospec(spec=Foo)).
def test_something(foo: Foo):
# I'd like to find a way for this to be accepted by mypy.
# error: "Callable[[int], str]" has no attribute "return_... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9778.py | Python | T = typing.TypeVar("T")
def callable_or_raise(foo: T) -> T:
if foo and not callable(foo):
raise ValueError("bad!")
return foo
def check(x: object) -> bool:
return callable(x)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9779.py | Python | @dataclass
class Passport:
byr: int
@property
def byr(self) -> int:
return self._byr
@byr.setter
def byr(self, value) -> None:
if int(value) < 1920 or int(value) > 2002:
raise Exception("Birth year must be between 1920 and 2002")
self._byr = int(value)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9785.py | Python | import collections
import re
PATTERN = re.compile('^([^ ]+ [^ ]+) bags contain (.*)$')
BAG_RE = re.compile(r'(\d+) ([^ ]+ [^ ]+)')
def compute(s: str) -> int:
parents = collections.defaultdict(list)
for line in s.splitlines():
match = PATTERN.match(line)
assert match
k = match[1]
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9791.py | Python | from typing import Union, Tuple, List
variable: List[Union[Tuple[int, int], Tuple[str, str]]] = []
element1 = variable[0]
print(element1[0] + element1[1])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9805.py | Python | from typing import Generic, TypeVar
T = TypeVar('T')
U = TypeVar('U')
class Data(Generic[T]): ...
class Container(Generic[T]):
def clone(self: U) -> U: ...
class Example(Generic[T]):
def example(self) -> None:
container = Container[Data[T]]()
clone = container.clone()
reveal_type(con... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9807.py | Python | from typing import List, TypeVar, Union
It = Union[str, int]
T = TypeVar("T")
def foo(a: Union[T, bool], b: List[T]) -> None: ...
def bar(a: T, b: List[T]) -> None: ...
it: It
data: List[It]
foo(it, data) # Cannot infer type argument 1 of "foo"
bar(it, data)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9810.py | Python | import functools
from typing import Iterable, TypeVar, Callable
T1 = TypeVar('T1')
T2 = TypeVar('T2')
def chain(
functions: Iterable[Callable[[T1], T1]]
) -> Callable[[T1], T1]:
def compose(
f: Callable[[T1], T1],
g: Callable[[T1], T1]
) -> Callable[[T1], T1]:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9815.py | Python | from typing import ClassVar, Generic, TypeVar
from Phidget22.Phidget import Phidget as Phidget22PhidgetAPI # Ignored in config
TKeys = TypeVar("TKeys")
class Base(Phidget22PhidgetAPI, Generic[TKeys]):
foo: ClassVar[TKeys]
# If this is not commented out, the bug surfaces
def __init__(self):
sup... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9822.py | Python | from typing import Union
foo: Union[str, bytes]
"zoo" in foo # no error
"zoo" + foo # err: Unsupported operand types for + ("str" and "bytes")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9827.py | Python | import sys
from typing import Any, Mapping, Type, TypeVar, cast
import typeguard
TD = TypeVar('TD')
def check_typed_dict(value: Mapping[Any, Any], expected_type: Type[TD]) -> TD:
"""
Validates the given dict against the given TypedDict class, and wraps the value as the given TypedDict type.
This is a sh... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9829.py | Python | x = [1, 2, 3]
x.append(4)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9838.py | Python | import abc
class IClass(metaclass=abc.ABCMeta):
"""Base class"""
class A(IClass):
def __init__(self, el: str, a: IClass) -> None:
self._el = el
self._a = a
class B(IClass):
def __init__(self, b: float) -> None:
self._b = b
def C(b):
return A('-', B(b))
class D(IClass):
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9843.py | Python | from typing import Protocol
class ProtocolInstance:
def __call__(self) -> str: ...
class NotProtocolInstance:
# equivalently, just remove __call__
def __call__(self, value: int) -> int: ...
class SomeProtocol(Protocol):
def __call__(self) -> str: ...
a: SomeProtocol = NotProtocolInstance # false ne... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9850.py | Python | foo: List[Literal['a', 'b']] = ['a', 'b', 'a']
if foo[0] == 'a':
print('a')
exit()
foo.pop(0)
reveal_type(foo[0])
if foo[0] == 'a':
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9858.py | Python | from typing import Callable, NamedTuple
class Foo(NamedTuple):
x: int
def __call__(self) -> int:
return self.x
foo: Callable[[], int] = Foo(42)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9862.py | Python | import functools
from typing import Generic, TypeVar
T = TypeVar("T")
class A(Generic[T]):
@property
def field1(self) -> T:
raise NotImplementedError
@functools.cached_property
def field2(self) -> T:
raise NotImplementedError
class B(A[None]):
@property
def field1(self) -> ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9864.py | Python | import os
filenames = map(os.path.basename, ["hello/world.txt"])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9870.py | Python | from typing import Callable, Optional
def f(func: Optional[Callable[[], None]] = None) -> None:
if func is None:
def func() -> None:
pass
func()
from typing import Callable, Optional
def f(func: Optional[Callable[[], None]] = None) -> None:
if func is None:
def _func() -> Non... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9875.py | Python | from dataclasses import field, dataclass
@dataclass
class C:
some_int: int
some_str: str = field(metadata={"doc": "foo"})
another_int: int
c = C(42, "bla", 43)
def doc(documentation: str):
return field(metadata={"doc": documentation})
@dataclass
class C:
some_int: int
some_str: str = doc("fo... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9876.py | Python | from abc import ABC, abstractmethod
from typing import Any, Awaitable, Callable, TypeVar, cast
T = TypeVar('T')
def dec(args: Any) -> Callable[..., Awaitable[T]]:
def dec2(f: Callable[..., Awaitable[T]]) -> Awaitable[T]:
async def wrapper(*args:Any, **kwargs:Any) -> T:
print(args)
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9884.py | Python | MyDict = TypedDict('MyDict', {'foo': int, 'bar': bool})
def fn() -> MyDict:
pass
def fn() -> TypedDict({'foo': int, 'bar': bool}):
pass
def fn() -> TypedDict(foo=int, bar=bool):
pass
MyType = TypedDict({
'foo': int,
'bar': TypedDict({
'baz': int,
})
})
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9890.py | Python | from typing import Optional, List
list_with_none: List[Optional[int]] = [None, 1, 2]
filtered = filter(lambda v: v is not None, list_with_none)
reveal_type(filtered)
# Revealed type is 'typing.Iterator[Union[builtins.int, None]]'
list_of_tuples: List[Tuple[Optional[int], Optional[int]]]
filter(lambda v: v[0] is no... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9892.py | Python | from typing import List, Union
def foo() -> Union[List[str], List[int]]:
return []
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9898.py | Python | import typing as t
T = t.TypeVar('T', covariant=True)
Y = t.TypeVar('Y')
class Nothing(t.Generic[T]):
def chain_none(self: 'Nothing[t.Optional[Y]]') -> 'Nothing[Y]':
return self # type: ignore
class Just(t.Generic[T]):
def __init__(self, val: T) -> None:
self._value = val
def chain_no... | 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.