File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -1716,17 +1716,20 @@ def add_allowed_assignments(
1716
1716
"add_allowed_assignments expects a non-empty variables array"
1717
1717
)
1718
1718
1719
- ct = Constraint (self )
1719
+ ct : Constraint = Constraint (self )
1720
1720
model_ct = self .__model .constraints [ct .index ]
1721
1721
model_ct .table .vars .extend ([self .get_or_make_index (x ) for x in variables ])
1722
- arity = len (variables )
1722
+ arity : int = len (variables )
1723
1723
for t in tuples_list :
1724
1724
if len (t ) != arity :
1725
1725
raise TypeError ("Tuple " + str (t ) + " has the wrong arity" )
1726
- ar = []
1727
- for v in t :
1728
- ar .append (cmh .assert_is_int64 (v ))
1729
- model_ct .table .values .extend (ar )
1726
+
1727
+ # duck-typing (no explicit type checks here)
1728
+ try :
1729
+ model_ct .table .values .extend (a for b in tuples_list for a in b )
1730
+ except ValueError as ex :
1731
+ raise TypeError (f"add_xxx_assignment: Not an integer or does not fit in an int64_t: { ex .args } " ) from ex
1732
+
1730
1733
return ct
1731
1734
1732
1735
def add_forbidden_assignments (
@@ -1760,7 +1763,7 @@ def add_forbidden_assignments(
1760
1763
)
1761
1764
1762
1765
index = len (self .__model .constraints )
1763
- ct = self .add_allowed_assignments (variables , tuples_list )
1766
+ ct : Constraint = self .add_allowed_assignments (variables , tuples_list )
1764
1767
self .__model .constraints [index ].table .negated = True
1765
1768
return ct
1766
1769
@@ -2751,7 +2754,7 @@ def get_interval_var_from_proto_index(self, index: int) -> IntervalVar:
2751
2754
2752
2755
# Helpers.
2753
2756
2754
- def __str__ (self ):
2757
+ def __str__ (self ) -> str :
2755
2758
return str (self .__model )
2756
2759
2757
2760
@property
You can’t perform that action at this time.
0 commit comments