From f212769bbc9a67a577fd2325f969f09b377ead04 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sun, 15 Jan 2023 10:16:18 -0800 Subject: [PATCH] Add type stubs and py.typed for icecream This'll allow icecream to be included without breakage in packages that peform type checking. It's very _loose_ typing, but hopefully it'll be enough to start? - generated an initial bundle of type stubs - enabled stubtest in the py39 test for tox - packaged py.typed and *.pyi in the sdist and pacakges --- icecream.pyi | 1 + icecream/__init__.pyi | 3 +++ icecream/__version__.pyi | 3 +++ icecream/builtins.pyi | 6 +++++ icecream/coloring.pyi | 22 ++++++++++++++++++ icecream/icecream.pyi | 49 ++++++++++++++++++++++++++++++++++++++++ icecream/py.typed | 0 setup.py | 1 + tox.ini | 10 ++++++++ 9 files changed, 95 insertions(+) create mode 100644 icecream.pyi create mode 100644 icecream/__init__.pyi create mode 100644 icecream/__version__.pyi create mode 100644 icecream/builtins.pyi create mode 100644 icecream/coloring.pyi create mode 100644 icecream/icecream.pyi create mode 100644 icecream/py.typed diff --git a/icecream.pyi b/icecream.pyi new file mode 100644 index 0000000..574d7ca --- /dev/null +++ b/icecream.pyi @@ -0,0 +1 @@ +from .icecream import * diff --git a/icecream/__init__.pyi b/icecream/__init__.pyi new file mode 100644 index 0000000..3f25af0 --- /dev/null +++ b/icecream/__init__.pyi @@ -0,0 +1,3 @@ +from .icecream import * +from .builtins import install as install, uninstall as uninstall +from os.path import dirname as dirname diff --git a/icecream/__version__.pyi b/icecream/__version__.pyi new file mode 100644 index 0000000..64380b4 --- /dev/null +++ b/icecream/__version__.pyi @@ -0,0 +1,3 @@ +__contact__: str +__url__: str +__description__: str diff --git a/icecream/builtins.pyi b/icecream/builtins.pyi new file mode 100644 index 0000000..753dac2 --- /dev/null +++ b/icecream/builtins.pyi @@ -0,0 +1,6 @@ +from typing import Any + +builtins: Any + +def install(ic: str = ...) -> None: ... +def uninstall(ic: str = ...) -> None: ... diff --git a/icecream/coloring.pyi b/icecream/coloring.pyi new file mode 100644 index 0000000..808cbfa --- /dev/null +++ b/icecream/coloring.pyi @@ -0,0 +1,22 @@ +from typing import Dict +from pygments.style import Style +from pygments.token import _TokenType + +class SolarizedDark(Style): + BASE03: str + BASE02: str + BASE01: str + BASE00: str + BASE0: str + BASE1: str + BASE2: str + BASE3: str + YELLOW: str + ORANGE: str + RED: str + MAGENTA: str + VIOLET: str + BLUE: str + CYAN: str + GREEN: str + styles: Dict[_TokenType, str] diff --git a/icecream/icecream.pyi b/icecream/icecream.pyi new file mode 100644 index 0000000..ea83aa8 --- /dev/null +++ b/icecream/icecream.pyi @@ -0,0 +1,49 @@ +import executing # type: ignore +import pprint +from typing import Any +from collections.abc import Generator + +PYTHON2: bool + +def bindStaticVariable(name, value) -> None: ... +def colorize(s) -> None: ... +def supportTerminalColorsInWindows() -> Generator[None, None, None]: ... +def stderrPrint(*args) -> None: ... +def isLiteral(s) -> None: ... +def colorizedStderrPrint(s) -> None: ... + +DEFAULT_PREFIX: str +DEFAULT_LINE_WRAP_WIDTH: int +DEFAULT_CONTEXT_DELIMITER: str +DEFAULT_OUTPUT_FUNCTION = colorizedStderrPrint +DEFAULT_ARG_TO_STRING_FUNCTION = pprint.pformat +NO_SOURCE_AVAILABLE_WARNING_MESSAGE: str + +def callOrValue(obj) -> None: ... + +class Source(executing.Source): + def get_text_with_indentation(self, node) -> None: ... + +def prefixLinesAfterFirst(prefix, s) -> None: ... +def indented_lines(prefix, string) -> None: ... +def format_pair(prefix, arg, value) -> None: ... +def singledispatch(func) -> None: ... +def argumentToString(obj) -> None: ... + +class IceCreamDebugger: + lineWrapWidth: int + contextDelimiter: str + enabled: bool + prefix: str + includeContext: bool + outputFunction: Any + argToStringFunction: Any + contextAbsPath: str + def __init__(self, prefix=..., outputFunction=..., argToStringFunction=..., includeContext: bool = ..., contextAbsPath: bool = ...) -> None: ... + def __call__(self, *args) -> None: ... + def format(self, *args) -> None: ... + def enable(self) -> None: ... + def disable(self) -> None: ... + def configureOutput(self, prefix=..., outputFunction=..., argToStringFunction=..., includeContext=..., contextAbsPath=...) -> None: ... + +ic: IceCreamDebugger diff --git a/icecream/py.typed b/icecream/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index 078bb91..6f4e13f 100755 --- a/setup.py +++ b/setup.py @@ -79,6 +79,7 @@ def run_tests(self): platforms=['any'], packages=find_packages(), include_package_data=True, + package_data={"icecream": ["py.typed", "*.pyi"]}, classifiers=[ 'License :: OSI Approved :: MIT License', 'Natural Language :: English', diff --git a/tox.ini b/tox.ini index 313f038..b5563f7 100644 --- a/tox.ini +++ b/tox.ini @@ -6,3 +6,13 @@ description = run unittest commands = python -m unittest + +[testenv:py39] +deps = + {[testenv]deps} + mypy + +commands = + python -m unittest + python3 -m mypy --install-types --non-interactive + python3 -m mypy.stubtest --ignore-missing-stub icecream