Skip to content

Commit

Permalink
⬆️ Upgrade dependencies and apply new formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davnn committed Sep 18, 2024
1 parent 8ca8199 commit 516ccf5
Show file tree
Hide file tree
Showing 9 changed files with 1,568 additions and 1,261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python: [ "3.9", "3.10", "3.11" ]
python: [ "3.10", "3.11", "3.12" ]
uses: ./.github/workflows/setup.yml
with:
os: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: safecheck
channels:
- conda-forge
dependencies:
- conda-forge::python=3.9
- conda-forge::python=3.10
2,710 changes: 1,518 additions & 1,192 deletions poetry.lock

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "safecheck"
version = "0.3.1"
version = "0.4.0"
description = "Utilities for typechecking, shapechecking and dispatch."
readme = "README.md"
authors = ["David Muhr <[email protected]>"]
Expand Down Expand Up @@ -38,39 +38,39 @@ classifiers = [
]

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
beartype = { version = "^0.16" }
jaxtyping = { version = "^0.2.24" }
python = ">=3.10,<3.13"
beartype = { version = ">0.15 <0.19" }
jaxtyping = { version = "^0.2" }
typing-extensions = { version = "^4.0" }

[tool.poetry.group.dev.dependencies]
# testing
pytest = "^7.4.3"
pytest = "^8.3.3"
pytest-html = "^4.1.1"
pytest-benchmark = "^4.0.0"
hypothesis = "^6.92.2"
hypothesis = "^6.112.1"
# coverage
coverage = "^7.4.0"
pytest-cov = "^4.1.0"
coverage-badge = "^1.1.0"
coverage = "^7.6.1"
pytest-cov = "^5.0.0"
coverage-badge = "^1.1.2"
# linting
ruff = "^0.1.9"
pre-commit = "^3.6.0"
black = "^23.12.1"
ruff = "^0.6.5"
pre-commit = "^3.8.0"
black = "^24.8.0"
# typing
pyright = "^1.1.344"
typing-extensions = "^4.9.0"
pyright = "^1.1.380"
typing-extensions = "^4.12.2"
# safety
bandit = "^1.7.6"
safety = "^2.3.5"
bandit = "^1.7.9"
safety = "^3.2.7"
# test data
numpy = "^1.26.2"
numpy = "^2.1.1"
torch = [
{ version = "^2.1.2", platform = "darwin", source = "pypi" },
{ version = "^2.1.2", platform = "win32", source = "pypi" },
{ version = "^2.1.2", platform = "linux", source = "pytorch-cpu" }
{ version = "^2.4.1", platform = "darwin", source = "pypi" },
{ version = "^2.4.1", platform = "win32", source = "pypi" },
{ version = "^2.4.1", platform = "linux", source = "pytorch-cpu" }
]
jax = { version = "^0.4.23", extras = ["cpu"] }
jax = { version = "^0.4.33", extras = ["cpu"] }
# notebooks
notebook = "^7.0.4"
# profiling
Expand Down Expand Up @@ -104,25 +104,25 @@ exclude = '''

[tool.ruff]
line-length = 120
select = ["ALL"]
extend-exclude = ["tests/", ".github/"]
force-exclude = true
ignore = [
lint.select = ["ALL"]
lint.ignore = [
"D203", # one blank line required before class docstring
"D213", # multi line summary should start at second line
"ANN101", # missing type annotation for `self` in method
"B905", # `zip()` without an explicit `strict=` parameter
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
# Combine multiple `from foo import bar as baz` statements with the same source
# (`foo`) into a single statement.
combine-as-imports = true
# Imports of the form `from foo import bar as baz` show one `import bar as baz`
# per line. Useful for __init__.py files that just re-export symbols.
force-wrap-aliases = true

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"

[tool.pyright]
Expand Down
1 change: 1 addition & 0 deletions safecheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
We additionally rename some of the functions to be independent of the underlying packages. For example,
it should be easily possible to switch from beartype to typeguard for runtime type checking.
"""

from warnings import filterwarnings

# re-export everything necessary from beartype, never use beartype itself.
Expand Down
10 changes: 4 additions & 6 deletions safecheck/_overload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
2. The overloads are iterated in definition-order until a matching overload is found.
3. If a matching overload is found (typecheck successful) return the result, otherwise raise an error.
"""

import sys
import warnings
from functools import wraps
Expand All @@ -32,16 +33,13 @@
]


class UnavailableOverloadError(Exception):
...
class UnavailableOverloadError(Exception): ...


class MissingOverloadError(Exception):
...
class MissingOverloadError(Exception): ...


class IncompatibleOverloadError(Exception):
...
class IncompatibleOverloadError(Exception): ...


def typecheck_overload(fn: CallableAnyT) -> CallableAnyT:
Expand Down
3 changes: 1 addition & 2 deletions safecheck/_typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
]


class MissingAnnotationError(Exception):
...
class MissingAnnotationError(Exception): ...


CallableAnyT = Callable[..., Any]
Expand Down
18 changes: 6 additions & 12 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,24 @@ def decorate(f):
return f


def f_basic(*_: int) -> None:
...
def f_basic(*_: int) -> None: ...


def f_shaped(*_: Shaped[NumpyArray, "n"]) -> None:
...
def f_shaped(*_: Shaped[NumpyArray, "n"]) -> None: ...


@overload
def f_overload(*_: int) -> None:
...
def f_overload(*_: int) -> None: ...


def f_overload(*_):
...
def f_overload(*_): ...


@overload
def f_overload_shaped(*_: Shaped[NumpyArray, "n"]) -> None:
...
def f_overload_shaped(*_: Shaped[NumpyArray, "n"]) -> None: ...


def f_overload_shaped(*_):
...
def f_overload_shaped(*_): ...


def test_no_overhead(benchmark):
Expand Down
33 changes: 11 additions & 22 deletions tests/test_safecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def f(self, x: basic_type) -> basic_type:
@pytest.mark.parametrize("basic_type", basic_types.keys())
def test_basic_type_overload_function(basic_type):
@overload
def f(x: basic_type) -> basic_type:
...
def f(x: basic_type) -> basic_type: ...

@typecheck_overload
def f(x):
Expand All @@ -116,8 +115,7 @@ def f(x):
def test_basic_type_overload_method(basic_type):
class A:
@overload
def f(self, x: basic_type) -> basic_type:
...
def f(self, x: basic_type) -> basic_type: ...

@typecheck_overload
def f(self, x):
Expand All @@ -138,8 +136,7 @@ def f(x: type_to_check) -> type_to_check:
@pytest.mark.parametrize("type_to_check", [union_type, generic_type])
def test_union_type_overload_function(type_to_check):
@overload
def f(x: type_to_check) -> type_to_check:
...
def f(x: type_to_check) -> type_to_check: ...

def f(x):
return x
Expand All @@ -151,8 +148,7 @@ def f(x):
def test_union_type_plain_method(type_to_check):
class A:
@overload
def f(self, x: type_to_check) -> type_to_check:
...
def f(self, x: type_to_check) -> type_to_check: ...

@typecheck_overload
def f(self, x):
Expand Down Expand Up @@ -185,8 +181,7 @@ def f(array: data_type[array_type, "..."]) -> data_type[array_type, "..."]:
@pytest.mark.parametrize("data_type", next(iter(data_types.values())).keys())
def test_array_type_overload_function(array_type, data_type):
@overload
def f(array: data_type[array_type, "..."]) -> data_type[array_type, "..."]:
...
def f(array: data_type[array_type, "..."]) -> data_type[array_type, "..."]: ...

@typecheck_overload
def f(array):
Expand All @@ -211,8 +206,7 @@ def f(self, array: data_type[array_type, "..."]) -> data_type[array_type, "..."]
def test_array_type_overload_method(array_type, data_type):
class A:
@overload
def f(self, array: data_type[array_type, "..."]) -> data_type[array_type, "..."]:
...
def f(self, array: data_type[array_type, "..."]) -> data_type[array_type, "..."]: ...

@typecheck_overload
def f(self, array):
Expand All @@ -230,8 +224,7 @@ def test_missing_annotation():


def test_missing_overload():
def f():
...
def f(): ...

class o:
__annotations__ = {}
Expand All @@ -245,20 +238,17 @@ class o:

def test_incompatible_overload():
@overload
def f(a, b):
...
def f(a, b): ...

def f(a):
...
def f(a): ...

with pytest.raises(IncompatibleOverloadError):
typecheck_overload(f)


def test_warn_overload_annotation():
@overload
def f(x: int) -> int:
...
def f(x: int) -> int: ...

def f(x: float) -> float:
return x
Expand All @@ -269,8 +259,7 @@ def f(x: float) -> float:

def test_unavailable_overload():
@overload
def f(x: int) -> int:
...
def f(x: int) -> int: ...

def f(x):
return x
Expand Down

0 comments on commit 516ccf5

Please sign in to comment.