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
''' comparing speed of new dataclass | |
with standard class attributes and slots, | |
running in 3.7.0b1''' | |
# subscribe to me: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1 | |
# I recommend reading PEP557: https://www.python.org/dev/peps/pep-0557/ | |
# this code at gist: http://bit.ly/slotsVdatclass | |
from dataclasses import dataclass | |
from timeit import timeit |
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 Any, TypeAlias, TypeVar, Union | |
from collections.abc import MutableSequence, Iterable, Mapping, Iterator | |
import copy | |
MS = TypeVar("MS", bound=MutableSequence) | |
Nested: TypeAlias = Mapping[Any, Union[Iterable, "Nested"]] | |
def nested_mapping_serializer( |
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
# -*- coding: utf-8 -*- | |
import logging | |
import os | |
import datetime | |
import time | |
class SingletonType(type): | |
_instances = {} |
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 types import SimpleNamespace | |
from typing import Any | |
from collections.abc import MutableSequence | |
class IndexableNamespace(SimpleNamespace, MutableSequence): | |
""" | |
An extension of the SimpleNamespace type. | |
The members of an IndexableNamespace instance can also be | |
accessed and modified by indexing. |