file_path stringlengths 3 280 | file_language stringclasses 66
values | content stringlengths 1 1.04M | repo_name stringlengths 5 92 | repo_stars int64 0 154k | repo_description stringlengths 0 402 | repo_primary_language stringclasses 108
values | developer_username stringlengths 1 25 | developer_name stringlengths 0 30 | developer_company stringlengths 0 82 |
|---|---|---|---|---|---|---|---|---|---|
code_snippets/mypy/8000-8999/8801.py | Python | from returns.curry import curry
class Test(object):
@curry
def __init__(self, a: int, b: str) -> None:
...
@curry
def some(self, a: int, b: str) -> None:
...
t: Test
# Works fine!
reveal_type(t.some)
# => Revealed type is 'Overload(def () -> Overload(def (a: builtins.int, b: builtins... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8806.py | Python | from typing import TypeVar, Generic, Union
class A:
pass
class ASub(A):
pass
class B:
pass
# Case 1... Success: no issues found
# T_co = TypeVar("T_co", covariant=True)
# Case 2... error: Value of type variable "T_co" of "SomeGeneric" cannot be "ASub" [type-var]
T_co = TypeVar("T_co", A, B, covariant=... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8814.py | Python | from decimal import Decimal
foo = [Decimal("1"), Decimal("2")]
sum(foo)
sum(foo) + sum(foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8819.py | Python | import sys
# This causes the error
try:
raise Exception
except Exception:
ex, val, _ = sys.exc_info()
print(f"Failed: {ex.__name__}: {val}") # Line 8
# This does not
try:
raise Exception
except Exception:
ex, val, _ = sys.exc_info()
if ex is not None: # Pointless comparison
print(f"F... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8823.py | Python | import sys
if sys.version_info >= (3, 7):
x: int = 'a'
import sys
if sys.version_info >= (3, 7):
x: int = 'a' # type: ignore
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8829.py | Python | from typing import Any, Optional, TypeVar
T = TypeVar("T")
def assert_not_none(value: Optional[T]) -> T:
assert value is not None
return value
def foo1(a: Optional[Any]) -> int:
return assert_not_none(a)[3]
def foo2(a: Optional[Any]) -> int:
assert a is not None
return a[3]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8836.py | Python | from typing import Type, Protocol
class MyProtocol(Protocol):
name: str
class MyImplementation(MyProtocol):
pass
foo: Type[MyProtocol] = MyImplementation
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8842.py | Python | with expr() as value:
do_good_stuff(value)
do_bad_stuff(value)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8843.py | Python | from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute
class MyModel(Model):
my_number = NumberAttribute()
my_optional_number = NumberAttribute(null=True)
reveal_type(MyModel().my_number) # note: Revealed type is 'int'
reveal_type(MyModel().my_optional_number) # note: Revealed type is... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8852.py | Python | from django.db import models
class Baz():
pass
class Foo(models.Model):
pass
class Bar(models.Model):
pass
def f(param: Foo) -> None:
pass
f(Foo())
f(Bar())
f(Baz())
from django.db import models
class Baz():
pass
class Foo(Baz):
pass
class Bar(Baz):
pass
def f(param: Foo) -> None:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8859.py | Python | import test
class C(test.A, test.B):
pass
from .a import *
from .b import *
from . import a
from . import b
__all__ = a.__all__ + b.__all__
class A:
pass
__all__ = ["A"]
class B:
pass
__all__ = ["B"]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8861.py | Python | from functools import reduce
tmp = reduce(lambda x, y: x + y, [[1], [2]])
# this works fine
result = list(tmp)
# but this one produces an error:
# Unsupported left operand type for + ("Iterable[int]")
result = list(reduce(lambda x, y: x + y, [[1], [2]]))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8862.py | Python | def foo(option: bool = None, **kwargs):
pass
def bar(option: str = '', **kwargs):
pass
d = {'test': True}
foo(**{'test': True})
foo(**d)
foo(other_option=True, option=True, **d)
foo(option=True, **{'test': True})
bar(**{'test': True}) # Error
bar(**d) # Error
bar(other_option=True, **d) # Error
bar(opti... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8865.py | Python | from typing import AbstractSet, Iterable, Optional, Set, TypeVar
T = TypeVar('T')
def intersection(seq: Iterable[AbstractSet[T]]) -> Optional[Set[T]]:
ret = None
for elem in seq:
if ret is None:
ret = set(elem)
else:
ret &= elem
return ret
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8867.py | Python | from typing import *
K = TypeVar("K", bound=Hashable)
V = TypeVar("V")
@overload
def dict_get_factory(dictionary: Dict[K, V],
key: K,
factory: Callable[[], V],
takes_key: Literal[False]) -> V: ...
@overload
def dict_get_factory(dictionary: Dict[K, V]... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8869.py | Python | from types import MethodType
from typing import Callable
def describe(func: Callable[[], None]) -> str:
if isinstance(func, MethodType):
return 'bound method'
else:
return 'other callable'
class C:
def m(self) -> None:
pass
print(describe(C().m))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8871.py | Python | T = TypeVar("T")
class A(Generic[T]):
def __init__(self, a: T) -> None:
self.a = a
def __str__(self) -> str:
if self.a is None:
return "Foo"
return "Bar"
class B(A[None]): ...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8873.py | Python | from abc import ABC, abstractmethod
from typing import Generic, TypeVar
A = TypeVar('A')
B = TypeVar('B')
C = TypeVar('C')
class TwoTypes(Generic[A, B]): pass
class ReproBase(ABC, Generic[C]):
@abstractmethod
def repro(self, a: A) -> TwoTypes[C, A]: pass
class ReproSub(ReproBase[C]):
@abstractmethod
def r... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8874.py | Python | import json
json_kwargs = dict(indent=2)
json.dumps({}, **json_kwargs)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8877.py | Python | from typing import TypeVar, Generic
from abc import abstractmethod, ABC
K = TypeVar('K')
class Metric(ABC, Generic[K]):
@abstractmethod
def sum(self, other: "Metric[K]") -> "Metric[K]":
pass
class MyFloatMetric(Metric[float]):
def sum(self, other: "MyFloatMetric") -> "MyFloatMetric":
r... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8881.py | Python | T = TypeVar('T')
class JSONSerialized(str, Generic[T]):
"""Strong type for the JSON serialized version of a type."""
@overload
def json_serialize(value: None) -> None:
"""Serialize value to its strong-typed JSON string type."""
@overload
def json_serialize(value: T) -> JSONSerialized[T]:
"""Serialize val... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8883.py | Python | class _AuthParamsPassword(TypedDict):
grant_type: Literal["password"]
email: str
password: str
class _AuthParamsRefresh(TypedDict):
grant_type: Literal["refresh_token"]
refresh_token: str
AuthParams = Union[_AuthParamsPassword, _AuthParamsRefresh]
class _TokenParamsPassword(TypedDict):
grant_ty... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8890.py | Python | # typed_dict_test.py
from typing import TypedDict
class D(TypedDict):
a: str
b: int
d_untyped = {"a": "foo", "b": 1}
d0 = D({"a": "foo", "b": 1}) # The only one that works
print(d0)
d1 = D(d_untyped)
print(d1)
d2 = D(**d_untyped)
print(d2)
d3 = D(dict(d_untyped))
print(d3)
d4 = D(dict(**d_untyped))
pri... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8896.py | Python | args = {'percent': percentage}
return cast(bool, await self._vehicle._command('set_charge_limit', args))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8900.py | Python | from typing import Any, Callable, TypeVar, _T as T
def bar() -> None:
def inner() -> None:
it.encode() # error: Cannot determine type of 'it'
breaks()
it = ""
deco: Callable[[T], T]
@deco
def breaks() -> None: ...
from typing import Any, Callable, TypeVar
T = TypeVar("T")
deco: Callable[[... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8921.py | Python | from typing import Sequence, Union, Tuple, List, Iterable, Collection, Optional, TypeVar, TypedDict
class _FieldOpts(TypedDict, total=True):
fields: Sequence[Union[str, Sequence[str]]]
a: Sequence[Union[str, Sequence[str]]] = ("name",)
b: Tuple[Optional[str], _FieldOpts] = (None, {"fields": ("name",)})
c: Seque... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8922.py | Python | from typing import Callable, TypeVar
class Base:
pass
class Sub(Base):
pass
class Other:
pass
BT = TypeVar('BT', bound=Base)
def check(obj: BT) -> None:
pass
check(Base())
check(Sub())
check(Other())
Factory = Callable[[], BT]
def f() -> Other:
pass
fAny: Factory = f
fBase: Factor... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8926.py | Python |
from typing import Protocol
class Person(Protocol):
first_name: str
def greeting(self, message: str) -> str:
...
class FrenchPerson(Person):
prenom: str
def __init__(self, name: str):
self.prenom = name
def salutation(self, message: str) -> str:
return f"{message} {se... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8934.py | Python | from typing import Generic, TypeVar
T = TypeVar("T", int, float)
class Foo(Generic[T]):
def __init__(self, val: T):
self.data: T = val
def bar(x: T) -> Foo[T]:
return Foo(x)
x = bar(1)
x = bar(2.0) # error thrown by mypy
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8940.py | Python | from typing import Union, Dict, List, Literal
firstset = Union[Literal['a'], Literal['b'], Literal['c']]
secondset = Union[Literal['d'], Literal['e'], Literal['f']]
firstdict: Dict[firstset, int] = {'a': 2}
seconddict: Dict[secondset, float] = {'d': 3.0}
firstlist: List[firstset] = ['a', 'b', 'c']
secondlist: List[s... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8957.py | Python | from typing import Tuple, Iterable
class NineCell:
pass
class NineHouse(Tuple[NineCell, ...]):
name: str
def __new__(cls, name: str, iterable: Iterable[NineCell]) -> "NineHouse":
self = super().__new__(cls, iterable)
self.name = name
return self
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8968.py | Python | # test.py
from package import E
name = 'a'
val = E[name]
assert val == E.a
# package/__init__.pyi
import package.test_def
E = package.test_def.E
# package/test_def.py
from enum import Enum
class E(Enum):
a = 'a'
b = 'b'
c = 'c'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8976.py | Python | from dataclasses import dataclass
@dataclass(frozen=True)
class Foo:
attr: int
@dataclass(frozen=True)
class Bar(Foo):
def attr(self) -> int:
return 1
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8981.py | Python | from typing import Any, Generic, TypeVar
T = TypeVar('T', bound=int)
class C(Generic[T]):
x: T
c: C[Any] = C()
c.x = 123
c.x = 'abc'
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8993.py | Python | from abc import ABC, abstractmethod
from typing import Type
class ISolution(ABC):
@abstractmethod
def __init__(self, b: int):
pass
@abstractmethod
def func1(self, a: int) -> int:
pass
class MySolution(ISolution):
def __init__(self, b: int):
self._b = b
def func1(sel... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/8000-8999/8996.py | Python | from abc import ABC, abstractmethod
from typing import List, Type, Dict
class BaseModel(ABC):
@property
@classmethod
@abstractmethod
def model_code(cls) -> str:
pass
# model_code: str
class M1(BaseModel):
model_code = "m1"
class M2(BaseModel):
model_code = "m2"
class ModelMa... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9003.py | Python | def f(t: Type[T]) -> T: ...
from typing import *
from dataclasses import dataclass
T = TypeVar('T')
@dataclass
class P:
a: int
class Q(NamedTuple):
a: int
def create(t: Type[T]) -> T: ...
# These ones work
reveal_type(create(int))
reveal_type(create(str))
reveal_type(create(List[int]))
reveal_type(creat... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9005.py | Python | import enum
@enum.unique
class MyEnum(enum.Enum):
FOO = enum.auto()
BAR = enum.auto()
class MyClass:
__slots__ = (
"_my_value",
)
_my_value: MyEnum
def __init__(self) -> None:
super().__init__()
self._my_value = MyEnum.FOO
def do_thing(self) -> None:
if... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9010.py | Python | from luguru import logger
LOG_A = logger.opt(lazy=False)
LOG_B = logger.opt(lazy=True)
LOG_A.info('Test {}', lambda x: x) # should work
LOG_B.info('Test {}', lambda x: x) # error
logger.opt(lazy=False).info('Test {c}', c=lambda x: x) # should work
logger.opt(lazy=True).info('Test {d}', d=lambda x: x) # erro... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9013.py | Python | from typing import Any, Dict
class Foo(Any):
pass
d: Dict[Foo, Foo]
def bar(x: Dict[str, str]) -> None:
pass
bar(d) # error: Argument 1 to "bar" has incompatible type "Dict[Foo, Foo]"; expected "Dict[str, str]"
from typing import Any, Dict
class Foo(Any):
pass
foo: Foo
def bar(x: str) -> None:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9015.py | Python | from datetime import date, datetime
if datetime.now() < date.today():
print("that's a surprise!")
python_version=3.8
incremental=True
follow_imports=normal
warn_redundant_casts=True
warn_unused_ignores=True
strict_optional=True
strict_equality=True
no_implicit_optional=True
disallow_untyped_defs=True
disallow_any... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9023.py | Python | from typing import Callable, TypeVar, Union, overload
T = TypeVar('T')
U = TypeVar('U')
@overload
def call(*, f: Callable[[], T]) -> T: ...
@overload
def call(*, u: U) -> U: ...
def call(*, f: Callable[[], T] = None, u: U = None) -> Union[T, U, None]:
return f() if f else u
def call(*, f: None = None, u: U) ->... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9025.py | Python | class A:
def func_on_win_only() -> str:
assert sys.platform == "win32"
return sys.getwindowsversion()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9031.py | Python | # mypy version 0.770
from typing import Generic, TypeVar
T = TypeVar("T", int, str)
class A:
foo: int
class B(Generic[T]):
foo: T
class C(B[int], A):
pass
reveal_type(A().foo)
reveal_type(B().foo)
reveal_type(C().foo)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9040.py | Python | from typing import Any, Optional
def foo(baz: Any) -> int:
return 1
def bar1(baz: Any = 0) -> int:
reveal_type(baz)
baz = foo(baz)
reveal_type(baz)
return baz
def bar2(baz: Optional[Any] = 0) -> int:
reveal_type(baz)
baz = foo(baz)
reveal_type(baz)
return baz
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9042.py | Python | if sys.platform == "win32":
...
elif sys.platform == "linux" or (not TYPE_CHECKING and hasattr(select, "epoll")):
...
# At type-checking time, assume that all platforms that aren't win32 or linux are some kind of BSD
elif TYPE_CHECKING or (not TYPE_CHECKING and hasattr(select, "kqueue")):
...
else:
rais... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9053.py | Python | from typing import Union, Callable, Type
# similar to a get-only property
class MyProperty:
def __init__(self, func: Callable[['B'], int]) -> None:
self.func = func
def __get__(self, instance: 'B', owner: Type['B']) -> int:
return self.func(instance)
# This class has an attribute 'x'
class ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9075.py | Python | from typing import Callable, TypeVar
T = TypeVar('T')
F = TypeVar('F', bound=Callable[..., int])
def call(func: Callable[..., T], *args: object) -> T:
return func(*args) # ok
def call2(func: Callable[..., int], *args: object) -> int:
return call(func, *args) # ok
def call3(func: F, *args: object) -> int:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9085.py | Python | from abc import ABC, abstractmethod
from typing import Type, Dict, List
class Abstract(ABC):
@abstractmethod
def method(self):
pass
# this doesn't print an error, but should, because Abstract is not a concrete type
DICT: Dict[int, Type[Abstract]] = {0: Abstract}
# error as expected
DICT[1] = Abstract... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9091.py | Python | def f(x: int = None) -> None:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9095.py | Python | class Example:
[(j := i) for i in range(5)] # INVALID SYNTAX
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9099.py | Python | from typing import List
from typing_extensions import Literal
lit1: Literal[1]
lit2: Literal[2]
arr2 = [lit1, lit2]
reveal_type(arr2)
from typing import List
from typing_extensions import Literal
lit1: Literal[1]
lit2: Literal[2, 3]
arr2 = [lit1, lit2]
reveal_type(arr2)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9104.py | Python | class A:
def f(self):
raise NotImplementedError
def g(self):
"""A is not an abstract base class"""
return "Hello World"
class B(A):
def f(self):
return 5
class C:
def f(self):
pass
class A:
def f(self) -> None: ...
def g(self): ...
class B(A):
def... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9105.py | Python | # test-requirements.txt
mypy
lxml<4
# test-requirements.txt
mypy[report]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9111.py | Python | import asyncio
from typing import NoReturn, Set
tasks: Set[asyncio.Task[NoReturn]] = set()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9113.py | Python | CONFIG_FILES = CONFIG_FILE + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9117.py | Python | Foo = TypedDict('Foo', {
'bar': int,
})
foo = Foo({'bar': 42})
d = {
'other': 2,
**foo, # Argument 1 to "update" of "dict" has incompatible type "Foo"; expected "Mapping[str, int]"
**dict(foo), # Argument 1 to "dict" has incompatible type "Foo"; expected "Mapping[str, int]"
}
d.update(foo) # Argumen... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9118.py | Python | from typing import Protocol
class SomeProtocol(Protocol):
y : int
x : int = 3
class Class(SomeProtocol):
pass
def test1() -> None:
y: int = Class.y # runtime error. mypy should catch it?
def test2() -> None:
x: int = Class.x # runs fine, but should probably be a mypy error?
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9122.py | Python | [1, None].sort()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9128.py | Python | from typing import Dict, Any
params: Dict[str, Any] = {}
a: Dict[str, Any] = params.get("abc", set())
reveal_type(a)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9134.py | Python | from typing import Any
class A:
doc = ""
class B(A):
# remove "-> Any" to make mypy happy
@property
def doc(self) -> Any:
return ""
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9137.py | Python | import sys
from types import TracebackType
from typing import Optional as Opt, Tuple, Type, Union
class Event:
exc_info: Opt[Union[Tuple[Type[BaseException],BaseException,TracebackType],Tuple[None,None,None]]] = None
def foo ( event: Event ) -> None:
try:
assert False
except Exception:
event.exc_info = *sys.ex... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9153.py | Python | type_hints = typing.get_type_hints(...) # Dict[str, Any]
if k in type_hints:
...
origin = typing.get_origin(...) # Any
if origin is Literal:
...
elif origin is list:
...
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9155.py | Python | from typing import TypeVar, Generic, List, Sequence
T = TypeVar('T')
I = TypeVar('I')
class B(Generic[T]):
def __init__(self, t: T, a: Sequence[I], c: Sequence[I]):
self.t = t
self.b: Sequence[object] = [*a, *c]
c = B[int] (15, ['a'], ['b', 'c']) # mypy rejects this
b = B[int, str](15, ['a'], ['b', 'c'... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9159.py | Python | from typing import Optional, Tuple, TypeVar
_T = TypeVar("_T")
_U = TypeVar("_U")
def promote_optional(tup: Tuple[Optional[_T], Optional[_U]]) -> Optional[Tuple[_T, _U]]:
for val in tup:
if val is None:
return None
return tup
def promote_optional2(tup: Tuple[Optional[_T], Optional[_U]]) ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9160.py | Python | class Foo:
def __init__(self) -> None:
self._d = {'a': 1}
def __setattr__(self, name: str, value: Any) -> None:
if hasattr(self, '_d'):
self._d[name] = value
else:
super(self.__class__, self).__setattr__(name, value)
@property
def a(self) -> int:
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9168.py | Python | if name in ['visible', 'value', 'locked']:
obj[name] = self.use_var_expr(scope, value)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9169.py | Python | import typing as t
from mypy_boto3.ec2.type_defs import (
DescribeInstancesResultTypeDef,
FilterTypeDef,
InstanceNetworkInterfaceAttachmentTypeDef,
InstanceNetworkInterfaceTypeDef,
InstanceStateTypeDef,
InstanceTypeDef,
PlacementTypeDef,
ReservationTypeDef,
TagTypeDef,
)
x: t.List[... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9176.py | Python | from itertools import chain
from typing import List
ints_of_ints: List[List[int]]
c = filter(lambda ints: len(ints), ints_of_ints) # ok
reveal_type(c) # typing.Iterator[builtins.list[builtins.int]]
d = chain.from_iterable(filter(lambda ints: len(ints), ints_of_ints)) # mypy: error arg-type - Argument 1 to "len" h... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9185.py | Python | @enum.unique
class MyEnumClass(Enum, metaclass=MyEnumMetaClass):
OUT_OF_STOCK = "Out of Stock"
LOW_STOCK = "Low Stock"
IN_STOCK = "In Stock"
EXCESS = "Excess"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9186.py | Python | from typing import Any, AnyStr
def foo(arg1: AnyStr, arg2: AnyStr) -> None: ...
bar: Any = ""
foo(1, "") # Error correctly reported
foo(b"", bar) # No error (correct)
foo(1, bar) # No error (false negative)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9191.py | Python | def ret_nothing() -> None:
pass
def use_nothing() -> None:
ret = ret_nothing()
async def async_ret_nothing() -> None:
pass
async def async_use_nothing() -> None:
ret = await async_ret_nothing()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9194.py | Python | def is_dev() -> str:
return settings.get("environment") == "dev"
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9195.py | Python | from typing import Tuple, TypeVar
import collections
N = collections.namedtuple("N", "name")
T = TypeVar("T", N, Tuple[N, N])
# T = TypeVar("T", N, Tuple[N, ...])
def get_name_bad(item: T) -> str:
return item.name if isinstance(item, N) else item[0].name
def get_name_good(item: T) -> str:
if isinstance(ite... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9198.py | Python | class ClassA:
def attribute(self):
return None
class ClassB:
attribute = None
@classmethod
def create(cls):
assert not issubclass(cls, ClassA)
ClassB.create()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9200.py | Python | x = (1, 2, 3)
y = x[1:3]
z = x[slice(1, 3)]
reveal_locals()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9201.py | Python | # makes_bug.py
from typing import Generic, Type, TypeVar
T = TypeVar('T')
class Foo(Generic[T]):
def __init__(self, value: T) -> None: ...
@classmethod
def construct(cls) -> Foo[str]:
return cls('bar')
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9202.py | Python | import functools
from typing import Callable, cast, Generic, overload, Protocol, Type, TypeVar, Optional, TYPE_CHECKING, Union
T = TypeVar('T')
V = TypeVar('V')
# Arbitrary descriptor implementation.
class Property(Generic[T, V]):
def __init__(self, fn: Callable[[T], V]):
self.fn = fn
@overload
... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9213.py | Python | #!/usr/bin/env python3
from typing import (
Any,
Dict,
Optional,
)
def required_int() -> int:
x: Dict[str, Any] = {
"id": "12345",
}
return x.get("id")
def optional_int() -> Optional[int]:
x: Dict[str, Any] = {
"id": "12345",
}
return x.get("id")
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9214.py | Python | lambda s: re.split('[,:]', expand_path(s.strip()))
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9225.py | Python | class Base():
def __init__(self, x: int) -> None:
self.x = x
def whatsx(self) -> int:
return self.x
class Child(Base):
def __init__(self, x: int) -> None:
pass
# Note: no call to super(), nor defining self.x.
c = Child(3)
print(c.whatsx()) # mypy does not catch undefined c... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9226.py | Python | from typing import TypeVar, List
StrOrList = TypeVar('StrOrList', str, List[str])
def f(a: StrOrList) -> StrOrList:
b = a if isinstance(a, list) else [a]
return b if isinstance(a, list) else b[0]
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9229.py | Python | from typing import Optional
def bar(var: str):
pass
def foo(var: Optional[str]=None):
var_not_None = not (var is None)
if var_not_None:
# var can only be a `str` at this point,
# but `mypy` complains that
# Argument 1 to "bar" 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/9230.py | Python | from typing import TypedDict
class FooDict(TypedDict):
foo: int
bar: int
foo = FooDict(foo=3, bar=3)
print(foo["foo"]) # Works
print(foo["bar"]) # Works
reveal_type(("foo", "bar")) # Revealed type is 'Tuple[Literal['foo']?, Literal['bar']?]'
for key in ("foo", "bar"):
reveal_type(key) # Revealed typ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9234.py | Python | import random
from typing import Union, Callable
class Wrapper:
def __init__(self, x):
self.x = x
def main() -> Union[Wrapper, int]:
wrap = Wrapper if random.random() < 0.5 else lambda x: x
return wrap(2)
class Wrapper:
def __init__(self, x: int) -> None:
self.x = x
def main() -> Un... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9253.py | Python | def foo() -> None:
iterator = map(list, ['hello', 'world']) # error: Argument 1 to "map" has incompatible type "Type[List[Any]]"; expected "Callable[[str], List[_T]]"
reveal_type(iterator)
iterator = map(lambda foo: list(foo), ["hello", "world"])
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9254.py | Python | from dataclasses import dataclass, InitVar
@dataclass
class Parent:
x: int
def __post_init__(self) -> None:
print("hi!")
@dataclass
class Child(Parent):
y: int
z: InitVar[int]
def __post_init__(self, z: int) -> None:
print("hi from child; z is", z)
class OtherParent:
def ... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9256.py | Python | from types import coroutine
from typing import Any, Iterator
async def my_async_func() -> None:
await my_coro_func()
@coroutine
def my_coro_func() -> Iterator[None]:
yield None
from types import coroutine
from typing import Any, Iterator
@coroutine
def my_coro_func() -> Iterator[None]:
yield None
async... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9264.py | Python | from typing import List, Optional
def example(data: Optional[List[int]] = None, size: int = 0) -> None:
buffer = bytearray(data if data else size)
print(buffer)
example(size=3)
example(data=[1, 2, 3])
if data:
buffer = bytearray(data)
else:
buffer = bytearray(size)
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9265.py | Python | from typing import Any, Callable, TypeVar
_FirstDecoratee = TypeVar("_FirstDecoratee", bound=Callable[..., Any])
_SecondDecoratee = TypeVar("_SecondDecoratee", bound=Callable[..., Any])
def basic_decorator(decoratee: _FirstDecoratee) -> _FirstDecoratee:
"decorate a function"
return decoratee
def decorator_... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9266.py | Python | from typing import TypeVar, Protocol, Any, Callable
import functools
F = TypeVar('F', bound=Callable[..., Any])
def implements(method: Any) -> Callable[[F], F]:
"""
Meant to be used as
class B:
@implements(IExpectedProtocol.method)
def method(self):
pass
Useful for knowin... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9279.py | Python | class list:
def __add__(self, x: List[_T]) -> List[_T]: ...
def __iadd__(self: _S, x: Iterable[_T]) -> _S: ...
class list:
def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
# __iadd__ unchanged
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9280.py | Python | from typing import TypedDict, Any, cast
class JSONTask(TypedDict, total=False):
...
@staticmethod # type: ignore
def validate(d: Any) -> bool:
...
return True
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9282.py | Python | from typing import TypeVar, Type
T = TypeVar("T", bound="A")
class A:
@classmethod
def foo(cls: Type[T]) -> T:
print(cls.__qualname__)
return cls()
class B(A):
@classmethod
def foo(cls: Type[T]) -> T:
return super().foo()
B.foo()
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9305.py | Python |
T = TypeVar("T")
class ClosedUnderFormat(Protocol[T]):
def format(self: "ClosedUnderFormat"[T], other: "ClosedUnderFormat"[T]) -> "ClosedUnderFormat[T]":
pass
class ClosedUnderAddition(Protocol[T]):
def __add__(self: "ClosedUnderAddition"[T], other: "ClosedUnderAddition"[T]) -> "ClosedUnderAddition... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9318.py | Python | # type: ignore[misc] # Ignores 'Any' input parameter
from typing import Any, Iterable
JsonSerializable = Any
CsvSerializable = Iterable[Any]
from my_app.typing import JsonSerializable
def foo(data: JsonSerializable) -> None:
...
from typing import Any, Iterable
JsonSerializable = Any # type: ignore[misc] # Ig... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9319.py | Python | import enum
class C:
pass
class D(C, enum.IntFlag):
pass
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9322.py | Python | from typing import TypeVar, Generic
T = TypeVar("T")
class Foo(Generic[T]):
def __init__(self): ...
class Bar(Generic[T]): ...
class FooChild(Foo[Bar[T]]):
def __init__(self, blah: T):
Foo.__init__(self)
from typing import TypeVar, Generic
T = TypeVar("T")
class Foo(Generic[T]):
def __init__(... | Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9327.py | Python | @attr.s(auto_attribs = True)
class Dummy:
var: str
| Akuli/issue-downloader | 0 | Downloads code from GitHub issues and saves it to files | Python | Akuli | ||
code_snippets/mypy/9000-9999/9333.py | Python | from typing import Awaitable, Generic, TypeVar
T = TypeVar("T")
class Foo(Generic[T]):
contents: T
def get_from(foo: Foo[T]) -> Awaitable[T]:
async def get_it() -> T:
return foo.contents
return get_it()
async def test() -> None:
foo = Foo[int]()
foo.contents = 42
assert 42 == await g... | 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.