Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 14, 2024 17:03
Show Gist options
  • Save mypy-play/42984d3d79039de6eae05f68c80fac33 to your computer and use it in GitHub Desktop.
Save mypy-play/42984d3d79039de6eae05f68c80fac33 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from collections.abc import Sequence
from enum import Enum
from typing import Self, overload
class MyStr(Sequence["MyStr"]):
@overload
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: bytes, encoding: str = ..., errors: str = ...) -> Self: ...
class MyStrEnum(MyStr, Enum):
A = "a" # ok
B = b"b", "utf-8" # ok, see the typeshed definition of `str.__new__`
C = "too", "many", "arguments", "provided" # runtime error: TypeError: str() takes at most 3 arguments (4 given)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment