Skip to content

Instantly share code, notes, and snippets.

View rhettinger's full-sized avatar

Raymond Hettinger rhettinger

  • Mutable Minds, Inc.
  • Santa Clara, California
View GitHub Profile
@rhettinger
rhettinger / mymax10e.py
Created November 18, 2021 01:50
Type annotated pure python implementation of the builtin max() function
'Emulate max() as fully as possible in pure Python.'
# https://stackoverflow.com/questions/69997857/implementation-of-max-function-in-python/69997876#69997876
# https://github.com/python/mypy/issues/7231
from typing import TypeVar, Any, Iterator, Iterable, Optional
from typing import Union, Protocol, Callable, cast, Tuple, overload
class SupportsGT(Protocol):
@rhettinger
rhettinger / mymax.py
Created November 17, 2021 15:32
Emulate max() as fully as possible in pure Python.
'Emulate max() as fully as possible in pure Python.'
# https://stackoverflow.com/questions/69997857/implementation-of-max-function-in-python/69997876#69997876
from typing import TypeVar, Any, Iterator, Iterable, Optional
from typing import Union, Protocol, Callable, overload
class SupportsGT(Protocol):
def __gt__(self, other: Any) -> bool: