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 contextlib | |
from typing import ContextManager | |
from django.core import cache | |
from django.core.cache.backends.dummy import DummyCache | |
@contextlib.contextmanager | |
def disable_caches(*aliases: str) -> ContextManager[tuple[str, ...]]: | |
"""Temporarily disable django caching backends. By default, all connected |
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, TYPE_CHECKING | |
if TYPE_CHECKING: | |
from _typeshed import SupportsLessThan | |
def cmp(a: 'SupportsLessThan', b: 'SupportsLessThan') -> Optional[int]: | |
"""Return 1 if a > b, 0 if a == b, -1 if a < b, otherwise None. | |
>>> cmp(42, 69), cmp(666, 666), cmp(69, 42), cmp(0, float('nan')) |
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
class FancyGeneric: | |
def __class_getitem__(cls, params): | |
if not isinstance(params, tuple): | |
params = (params,) | |
newparams = [] | |
for param in params: | |
if isinstance(param, slice): | |
assert param.start is None and param.step is None |
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 sys | |
for x in (0.0, 1/10, -1/10, sys.float_info.max, sys.float_info.min, float('inf'), float('-inf'), float('NaN')): | |
print(f'{x}++ => {float_incr(x)}') | |
i, xi = 0, float('-inf') | |
while xi < float('inf'): | |
x = float_incr(xi) | |
assert x > xi | |
xi = x / 2 if x < 0 else x * 2 |
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 asyncio | |
async def task(): | |
print('task start') | |
await asyncio.sleep(.5) | |
print('task done') | |
async def run_tasks(): |
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
""" | |
This is valid (but ridiculous) syntax: | |
spam_with_eggs = Spam<<'eggs'>>('ham', 'bacon') | |
""" | |
class _TraitAlias: | |
__slots__ = ('__origin__', '__traits__') |
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 webbrowser | |
def main(): | |
return 42/0 | |
if __name__== '__main__': | |
try: | |
main() |
NewerOlder