Ticket #4954 (new defect)

Opened 6 months ago

Last modified 3 months ago

Words_over_Alphabet should check the type of input alphabet

Reported by: slabbe Owned by: slabbe
Priority: major Milestone: sage-4.1
Component: combinatorics Keywords: words alphabet
Cc: sage-combinat Reviewer(s):
Author(s): Merged in:

Description

Do

sage: W=Words('ab')
sage: W.alphabet?

and you get the following help example :

sage: from sage.combinat.words.words import Words_over_Alphabet
sage: W = Words_over_Alphabet([1,2,3])
sage: W.alphabet()
[1, 2, 3]
sage: from sage.combinat.words.words import OrderedAlphabet
sage: W = Words_over_Alphabet(OrderedAlphabet('ab'))
sage: W.alphabet()
Ordered Alphabet ['a', 'b']

The first of the above example is misleading. In fact, it is not usable :

sage: from sage.combinat.words.words import Words_over_Alphabet
sage: W = Words_over_Alphabet([1,2,3])
sage: W.alphabet()
[1, 2, 3]
sage: W([1,1,1,2,1,3])
Traceback (most recent call last):
...
AttributeError: 'list' object has no attribute 'rank'

The problem comes from the fact that Words_over_Alphabet doesn't check the input alphabet before asigning it to self._alphabet(). It should either do alphabet=OrderedAlphabet(alphabet) before or check the type of the input alphabet with a isinstance.

Change History

Changed 6 months ago by slabbe

  • owner changed from mhansen to slabbe

Changed 3 months ago by nthiery

  • cc sage-combinat added
Note: See TracTickets for help on using tickets.