View asyncio_eventloop_benchmark.py
This file contains 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 | |
import time | |
from time import perf_counter_ns | |
# noinspection PyPep8Naming | |
class ns_per_it: | |
__slots__ = 'n', 'res' | |
def __init__(self, n: int): |
View example.py
This file contains 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 | |
from run import main | |
@main(debug=True) | |
async def __amain__(): | |
await asyncio.sleep(0.1) | |
fp = open(__file__) |
View async_init.py
This file contains 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 | |
class AsyncInit: | |
def __await__(self): | |
async def _(): | |
await self.__ainit__() | |
return self | |
return _().__await__() |
View pause_django_caching.py
This file contains 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 |
View cmp.py
This file contains 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')) |
View generic_type_pattern_matching.py
This file contains 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 |
View demo.py
This file contains 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 |
View asyncio_shield_misleading.py
This file contains 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(): |
View traits.py
This file contains 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__') |
View main.py
This file contains 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() |