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 dataclasses import dataclass, field | |
| from datetime import datetime | |
| from typing import Optional, TypeVar | |
| T = TypeVar("T") | |
| def required() -> T: | |
| f: T |
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 collections import deque | |
| import logging | |
| import signal | |
| from threading import Condition, Event, Thread | |
| import time | |
| logging.basicConfig(level=logging.INFO) | |
| class Stop(Exception): |
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 Meta1(type): | |
| @classmethod | |
| def __prepare__(cls, *args): | |
| return {"decorator": lambda f: f, "prepared_attr": "prepared_attr_value"} | |
| class Meta2(type): | |
| def __new__(cls, name, bases, namespace): | |
| namespace["decorator"] = lambda f: f | |
| namespace["new_attr"] = "new_attr_value" |
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 concurrent.futures import ThreadPoolExecutor, TimeoutError | |
| class TimeoutIterable: | |
| """Iterable that exhausts if it takes longer than `timeout` seconds to obtain the next value.""" | |
| def __init__(self, iterable, timeout=None): | |
| self._it = iter(iterable) | |
| self.timeout = timeout |
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
| # Level 0 | |
| {"asdf": {"a": [1, 2, 3], "b": 500}, "qwerty": {"a": [4, 5, 6], "b": 1000}} | |
| # Level 1 | |
| { | |
| "asdf": {"a": [1, 2, 3], "b": 500}, | |
| "qwerty": {"a": [4, 5, 6], "b": 1000} | |
| } | |
| # Level 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
| from functools import wraps | |
| import logging | |
| import time | |
| logger = logging.getLogger(__name__) | |
| def timed(func): | |
| """This decoratorlogs the execution time for the decorated function.""" |