This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Iterator | |
| def fib(n: int) -> Iterator[int]: | |
| a, b = 0, 1 | |
| while a < n: | |
| yield a | |
| a, b = b, a + b | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import reveal_type | |
| def bug_wrong(my_list: list[tuple[int, str, str]]) -> bool: | |
| for _, *my_tuple in my_list: | |
| reveal_type(my_tuple) | |
| if my_tuple == ('foo', 'bar'): | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Optional | |
| from typing import reveal_type | |
| def bug_wrong(my_list: list[tuple[int, str, str]]) -> bool: | |
| for _, *my_tuple in my_list: | |
| reveal_type(my_tuple) | |
| if my_tuple == ('foo', 'bar'): | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Optional | |
| from typing import reveal_type | |
| def bug_wrong(my_list: list[tuple[int, str, str]]) -> bool: | |
| for _, *my_tuple in my_list: | |
| reveal_type(my_tuple) | |
| if my_tuple == ('foo', 'bar'): | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Generic, Protocol, TypeVar, reveal_type | |
| T = TypeVar("T") | |
| T_contra = TypeVar("T_contra", contravariant=True) | |
| S2 = TypeVar("S2") | |
| class ElementOpsMixin(Generic[S2]): | |
| def _sub(self: ElementOpsMixin[int], other: int) -> ElementOpsMixin[int]: ... # invariant | |
| class Supports_Sub(Protocol[T_contra, S2]): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import importlib.machinery | |
| import importlib.util | |
| class PatchedLoader(importlib.machinery.SourceFileLoader): | |
| pass | |
| spec = importlib.util.spec_from_file_location( | |
| "", "", loader=PatchedLoader("", "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import importlib.machinery | |
| import importlib.util | |
| class PatchedLoader(importlib.machinery.SourceFileLoader): | |
| pass | |
| spec = importlib.util.spec_from_file_location( | |
| "", "", loader=PatchedLoader("", "") | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foo: int = "bar" # type: ignore[assignment, ty:invalid-assignment] | |
| bar: int = "foo" # type: ignore[assignment] # ty: ignore[invalid-assignment] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x = 100 | |
| x = "Now I am a string" | |
| print(x.upper()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import TypeVar, Generic | |
| from abc import ABC, abstractmethod | |
| T = TypeVar("T") | |
| class SomeParent(ABC, Generic[T]): | |
| class Inner(ABC): | |
| @abstractmethod | |
| def get_t(self) -> T: |
NewerOlder