Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit cd6ba09

Browse files
committed
29524: more care with input of IntegerVectors
1 parent 10ed24e commit cd6ba09

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/sage/combinat/integer_vector.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from sage.combinat.integer_lists import IntegerListsLex
3535
from itertools import product
36+
import numbers
3637

3738
from sage.structure.parent import Parent
3839
from sage.structure.unique_representation import UniqueRepresentation
@@ -592,6 +593,13 @@ def __classcall_private__(cls, n=None, k=None, **kwargs):
592593
Traceback (most recent call last):
593594
...
594595
ValueError: k and length both specified
596+
597+
:trac:`29524`::
598+
599+
sage: IntegerVectors(3, 3/1)
600+
Traceback (most recent call last):
601+
...
602+
TypeError: 'k' must be an integer or a tuple, got Rational
595603
"""
596604
if 'length' in kwargs:
597605
if k is not None:
@@ -607,12 +615,12 @@ def __classcall_private__(cls, n=None, k=None, **kwargs):
607615
if n is None:
608616
return IntegerVectors_k(k)
609617

610-
try:
618+
if isinstance(k, numbers.Integral):
619+
return IntegerVectors_nk(n, k)
620+
elif isinstance(k, (tuple, list)):
611621
return IntegerVectors_nnondescents(n, tuple(k))
612-
except TypeError:
613-
pass
614-
615-
return IntegerVectors_nk(n, k)
622+
else:
623+
raise TypeError("'k' must be an integer or a tuple, got {}".format(type(k).__name__))
616624

617625
def __init__(self, category=None):
618626
"""

0 commit comments

Comments
 (0)