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