Skip to content

Instantly share code, notes, and snippets.

from dataclasses import dataclass, field
from functools import cached_property
def make_lambda():
return lambda x: x * 2
@dataclass(frozen=True)
class FuncHolderA:
from concurrent.futures import ThreadPoolExecutor, Future
from typing import Callable, TypeVar, Generic, Any
# 型変数の定義
A = TypeVar('A')
B = TypeVar('B')
# --- Par の実装 ---
from typing import Optional
class Event:
def __init__(self, name: str) -> None:
self.name = name
def __str__(self) -> str:
return self.name
from abc import ABC, abstractmethod
from enum import Enum, auto
class State(Enum):
NEW = auto()
RUNNING = auto()
SLEEPING = auto()
RESTART = auto()
ZOMBIE = auto()
from typing import Callable, Protocol
class Organizer(Protocol):
def organize_event(self) -> str:
...
class Musician:
def play(self) -> str:
from typing import Protocol
class Animal(Protocol):
def sound(self) -> str:
...
"""
構造的サブタイピングとは、オブジェクトやクラスが、あるインターフェースや型の要件を、その内部構造(メソッドや属性の存在)によって満たしているかどうかで判断する型システムのアプローチのこと
import argparse
from abc import ABCMeta, abstractmethod
from typing import Type
class Engine(metaclass=ABCMeta):
@abstractmethod
def start(self) -> None:
...
from typing import TypeVar, Generic, Callable, Optional
T = TypeVar("T")
U = TypeVar("U")
X = TypeVar("X")
R = TypeVar("R")
S = TypeVar("S")
A = TypeVar("A")
B = TypeVar("B")
import time
import random
import functools
from typing import Callable, TypeVar
# Python 3.10以降の場合
#from typing import ParamSpec
# Python 3.9以下の場合
from typing_extensions import ParamSpec
import os
from typing import Tuple, Protocol, runtime_checkable
# コマンドとして実行可能なオブジェクトのプロトコル
class Executable(Protocol):
def execute(self) -> None:
...
@runtime_checkable