Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn for duplicate registration #34

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "v0.7.1"
current_version = "v0.7.2"
commit = true
commit_args = "--no-verify"
tag = true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# totypes - Custom types for topology optimization
`v0.7.1`
`v0.7.2`

## Overview

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]

name = "totypes"
version = "v0.7.1"
version = "v0.7.2"
description = "Custom datatypes useful in a topology optimization context"
keywords = ["topology", "optimization", "jax", "inverse design"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/totypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (c) 2023 The INVRS-IO authors.
"""

__version__ = "v0.7.1"
__version__ = "v0.7.2"
__author__ = "Martin F. Schubert <[email protected]>"

__all__ = ["json_utils", "symmetry", "types"]
Expand Down
8 changes: 5 additions & 3 deletions src/totypes/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
import dataclasses
import json
import warnings
from typing import Any, Dict, Sequence, Tuple, Union

import jax.numpy as jnp
Expand Down Expand Up @@ -38,7 +39,7 @@ def register_custom_type(custom_type: Any) -> None:
f"Only dataclasses and namedtuples are supported, but got {custom_type}."
)
if custom_type in _CUSTOM_TYPE_REGISTRY.values():
raise ValueError(f"Duplicate custom type registration for {custom_type}.")
warnings.warn(f"Duplicate custom type registration for {custom_type}.")
prefix = _prefix_for_custom_type(custom_type)
_validate_prefix(prefix, list(_CUSTOM_TYPE_REGISTRY.keys()))
_CUSTOM_TYPE_REGISTRY[prefix] = custom_type
Expand All @@ -54,8 +55,9 @@ def _validate_prefix(test_prefix: str, existing_prefixes: Sequence[str]) -> None
for p in existing_prefixes:
if (
p.startswith(_PREFIX_ARRAY)
or p.startswith(test_prefix)
or test_prefix.startswith(p)
or p.startswith(_PREFIX_COMPLEX)
or (p.startswith(test_prefix) and p != test_prefix)
or (test_prefix.startswith(p) and p != test_prefix)
):
raise ValueError(
f"Prefix {test_prefix} confilcts with existing {existing_prefixes}."
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,5 @@ class MyClass123:
pass

json_utils.register_custom_type(MyClass123)
with self.assertRaisesRegex(ValueError, "Duplicate custom type registration"):
with self.assertWarnsRegex(UserWarning, "Duplicate custom type registration"):
json_utils.register_custom_type(MyClass123)
85 changes: 0 additions & 85 deletions tests/test_json_utils_server_client.py

This file was deleted.