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 | |
| import os | |
| import re | |
| re_enum = re.compile(r'\s*enum\s*(\w+)\s*(:.*)?\s*') | |
| re_enum_value = re.compile(r'\s*(\w+)(?:\s*=\s*(.+))?,?(?:\s*\/\/.*)?\s*') | |
| folders_blacklist = [ | |
| # 'Urho3D/Audio', | |
| # 'Urho3D/Container', | |
| # 'Urho3D/Core', |
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 enum import Enum | |
| class Foo(Enum): | |
| A = 1 | |
| B = 2 | |
| C = 3 | |
| def __str__(self): | |
| return self.name |
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
| """TypedEnum : type preserving enumeration metaclass.""" | |
| class TypedEnum(type): | |
| """This metaclass creates an enumeration that preserves isinstance(element, type).""" | |
| def __new__(mcs, cls, bases, classdict): | |
| """Discover the enum members by removing all intrinsics and specials.""" | |
| object_attrs = set(dir(type(cls, (object,), {}))) | |
| member_names = set(classdict.keys()) - object_attrs | |
| member_names = member_names - set(name for name in member_names if name.startswith("_") and name.endswith("_")) |
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
| # coding: utf-8 | |
| import abc | |
| from types import new_class | |
| from typeguard import check_type | |
| from contextlib import contextmanager | |
| def make_type_class(name, parent, type_declaration): | |
| def init(self, 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
| import enum | |
| class EnumWithDisplayName(enum.Enum): | |
| def __new__(cls, value, name=None): | |
| if not hasattr(cls, "_value_to_display_name"): | |
| cls._value_to_display_name = {} | |
| cls._display_name_to_value = {} | |
| if name is not None: | |
| if value in cls._value_to_display_name: |
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 psycopg2.extensions import QuotedString | |
| import enum | |
| # Usage: `cursor.execute("SELECT * FROM quotes WHERE " + Parser(query).parse().to_sql())` | |
| # Hopefully there won't be any SQL injection bugs... | |
| class Column(enum.Enum): | |
| ord = 1 | |
| pattern = 2 | |
| fts = 3 |
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 random | |
| class MyBase: | |
| """This is a base class""" | |
| def __init__(self, **kwargs): | |
| """Assign each key, value pair to our class instance""" | |
| for arg, val in kwargs.items(): | |
| self.__dict__[arg] = val |
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 defaultdict | |
| from enum import Enum | |
| class ElementTypes(Enum): | |
| PHONE = "PHONE" | |
| CAR = "CAR" | |
| class Registry: |
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
| #!/usr/bin/env python3 | |
| """Exploring python enum.""" | |
| import enum | |
| # from typing import Sequence | |
| class Simple(enum.Enum): | |
| A = 'a' | |
| B = '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
| import string | |
| import re | |
| from typing import Any, List, Dict | |
| class GracefulKeyFormatter(string.Formatter): | |
| def get_value(self, key: str, args: List[Any], kwargs: Dict[str, Any]) -> Any: | |
| """ | |
| Retrieve the value of the given key from the provided keyword arguments. | |