Repository: DanielSank/constraintula

Issue:
raise non-ValueError
In 8feb313825706ebc5e1ac2d1e0d3076576a0cc11 I added a `ValueError` when a system has no solution. I was thinking it would be a bit nicer to introduce a new error class (`NoSolution`?) to make this easier to catch.

Discussion:

Patch:
diff --git a/constraintula/__init__.py b/constraintula/__init__.py
index 87b9c83..51e7acd 100644
--- a/constraintula/__init__.py
+++ b/constraintula/__init__.py
@@ -14,7 +14,7 @@
 
 from sympy import sqrt, Symbol, symbols  # type: ignore
 
-from .core import constrain, make_wrapper, System
+from .core import constrain, make_wrapper, System, NoSolution
 
 
 __version__ = "0.3.0"
diff --git a/constraintula/core.py b/constraintula/core.py
index 6ba4e89..c5e6db3 100644
--- a/constraintula/core.py
+++ b/constraintula/core.py
@@ -50,6 +50,13 @@ import sympy
 from sympy import Expr, Symbol, symbols
 
 
+class NoSolution(Exception):
+    """Raised when a system has no solution."""
+
+    def __init__(self):
+        super().__init__("System has no solution")
+
+
 class System:
     """A system of constraints that can be solved for a subset of symbols.
 
@@ -288,7 +295,7 @@ def make_wrapper(
         # dict.
         if isinstance(values, list):
             if not len(values):
-                raise ValueError("System has no solution")
+                raise NoSolution()
             values = values[0]
 
         # Use `ty` to convert each solved value from the sympy type to either


Test patch:
diff --git a/constraintula_test.py b/constraintula_test.py
index 3a407bc..4e0a646 100644
--- a/constraintula_test.py
+++ b/constraintula_test.py
@@ -210,5 +210,5 @@ def test_constrain_with_mixed_types():
     assert isinstance(bar.y, float)
 
     # There is no integral solution
-    with pytest.raises(ValueError):
+    with pytest.raises(constraintula.NoSolution):
         Bar(x=1, y=0.1)