diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 46a8947..3130ecd 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -44,6 +44,7 @@ jobs: - name: Typecheck with mypy run: | poetry run mypy cassini + poetry run mypy tests --exclude=tests/extensions/cassini_lib/mock_libraries/ --exclude=tests/project_cases - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: diff --git a/binder/cas_project.py b/binder/cas_project.py index ddead11..c3d1760 100644 --- a/binder/cas_project.py +++ b/binder/cas_project.py @@ -1,4 +1,4 @@ -from cassini import Project, DEFAULT_TIERS +from cassini import Project, DEFAULT_TIERS, WorkPackage project = Project(DEFAULT_TIERS, __file__) diff --git a/cassini/meta.py b/cassini/meta.py index fb020e1..edb0d20 100644 --- a/cassini/meta.py +++ b/cassini/meta.py @@ -8,8 +8,7 @@ Generic, KeysView, List, - Optional, - Mapping, + overload, TypeVar, Union, Literal, @@ -288,6 +287,14 @@ def __set_name__(self, owner: object, name: str) -> None: if self.name is None: self.name = name + @overload + def __get__(self, instance: None, owner: object) -> Self: + pass + + @overload + def __get__(self, instance: object, owner: object) -> AttrType: + pass + def __get__( self, instance: Union[Any, None], owner: object ) -> Union[AttrType, Self]: diff --git a/pyproject.toml b/pyproject.toml index f383c55..94bd307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cassini" -version = "0.3.0a12" +version = "0.3.0a13" description = "A tool to structure experimental work, data and analysis using Jupyter Lab." authors = ["0Hughman0 "] license = "GPL-3.0-only" diff --git a/tests/test_highlights.py b/tests/test_highlights.py index 3ece2b2..24e6089 100644 --- a/tests/test_highlights.py +++ b/tests/test_highlights.py @@ -1,6 +1,6 @@ import pytest # type: ignore[import] -from cassini import DEFAULT_TIERS +from cassini import DEFAULT_TIERS, Project from cassini.testing_utils import get_Project, patch_project @pytest.fixture @@ -26,8 +26,8 @@ def mk_project(get_Project, tmp_path): return project -def test_add_highlight(mk_project) -> None: - project: Project = mk_project +def test_add_highlight(mk_project): + project = mk_project wp = project['WP1'] diff --git a/tests/test_meta.py b/tests/test_meta.py index 5ae256c..399d379 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -2,6 +2,8 @@ import pathlib import datetime +from typing_extensions import assert_type + import pytest # type: ignore[import] from cassini import HomeTierBase, NotebookTierBase from cassini.meta import MetaAttr, Meta, MetaCache, MetaValidationError @@ -134,6 +136,20 @@ def __init__(self): assert obj.with_default == 'squid' +# this test has to be run with mypy... which is confusing. +def test_meta_attr_inferred_types(tmp_path) -> None: + class MyClass: + a_str = MetaAttr(str, str) + + def __init__(self): + self.meta = Meta.create_meta(tmp_path / 'meta.json', owner=self) + + m = MyClass() + + assert_type(m.a_str, str) + assert_type(MyClass.a_str, MetaAttr[str, str]) + + def test_jsonable(mk_meta): meta = mk_meta