diff --git a/noxfile.py b/noxfile.py index a3588e164..d6434773c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,6 +3,7 @@ import functools import os import re +import sys from pathlib import Path from typing import Any, Callable, TypeVar @@ -160,7 +161,10 @@ def test_python(session: Session) -> None: """Run all Python checks""" session.notify("test_python_suite", posargs=session.posargs) session.notify("test_python_types") - session.notify("test_python_style") + if sys.version_info >= (3, 10): + session.notify("test_python_style") + else: + session.log("Skipping type checking - Python<3.10") session.notify("test_python_build") diff --git a/pyproject.toml b/pyproject.toml index 18a77f5a7..74157e0dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,3 +10,9 @@ ensure_newline_before_comments = "True" include_trailing_comma = "True" line_length = 88 lines_after_imports = 2 + +[tool.mypy] +ignore_missing_imports = "True" +warn_unused_configs = "True" +warn_redundant_casts = "True" +warn_unused_ignores = "True" diff --git a/setup.cfg b/setup.cfg index 293907987..4d693dcec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,6 @@ [bdist_wheel] universal=1 -[mypy] -ignore_missing_imports = True -warn_unused_configs = True -warn_redundant_casts = True -warn_unused_ignores = True - [flake8] ignore = E203, E266, E501, W503, F811, N802, N806 per-file-ignores = diff --git a/src/idom/_py_compat.py b/src/idom/_py_compat.py new file mode 100644 index 000000000..bcd3ac248 --- /dev/null +++ b/src/idom/_py_compat.py @@ -0,0 +1,6 @@ +__all__ = ["EllipsisType"] + +try: + from types import EllipsisType +except ImportError: + EllipsisType = type(Ellipsis) # pragma: no cover diff --git a/src/idom/backend/flask.py b/src/idom/backend/flask.py index 55e20618b..5a2853fbb 100644 --- a/src/idom/backend/flask.py +++ b/src/idom/backend/flask.py @@ -85,7 +85,7 @@ def run_server() -> None: if started: loop.call_soon_threadsafe(started.set) try: - server.current.serve_forever() # type: ignore + server.current.serve_forever() finally: loop.call_soon_threadsafe(stopped.set) diff --git a/src/idom/utils.py b/src/idom/utils.py index e8f9cfd01..282da4493 100644 --- a/src/idom/utils.py +++ b/src/idom/utils.py @@ -1,9 +1,12 @@ +from __future__ import annotations + from html.parser import HTMLParser as _HTMLParser from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, TypeVar +from ._py_compat import EllipsisType + _RefValue = TypeVar("_RefValue") -_UNDEFINED: Any = object() class Ref(Generic[_RefValue]): @@ -19,8 +22,8 @@ class Ref(Generic[_RefValue]): __slots__ = "current" - def __init__(self, initial_value: _RefValue = _UNDEFINED) -> None: - if initial_value is not _UNDEFINED: + def __init__(self, initial_value: _RefValue | EllipsisType = ...) -> None: + if initial_value is not ...: self.current = initial_value """The present value"""