markuskiller / textblob-de

German language support for TextBlob.
https://textblob-de.readthedocs.org
MIT License
104 stars 12 forks source link

TypeError: '<' not supported between instances of 'NoneType' and 'int' #23

Open RajK853 opened 1 year ago

RajK853 commented 1 year ago

How to reproduce the error

from textblob_de.packages import pattern_de

pattern_de.tenses("entschieden")

--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_19180/3404022709.py in <module>
----> 1 pattern_de.tenses("entschieden")

~/.local/share/virtualenvs/ZOyfachx/lib/python3.7/site-packages/textblob_de/ext/_pattern/text/de/inflect.py in tenses(self, verb, parse)
    467         """ Returns a list of possible tenses for the given inflected verb.
    468         """
--> 469         tenses = _Verbs.tenses(self, verb, parse)
    470         if len(tenses) == 0:
    471             # auswirkte => wirkte aus

~/.local/share/virtualenvs/ZOyfachx/lib/python3.7/site-packages/textblob_de/ext/_pattern/text/__init__.py in tenses(self, verb, parse)
   1786                         a.add(id1)
   1787         a = (TENSES[id][:-2] for id in a)
-> 1788         a = Tenses(sorted(a))
   1789         return a
   1790 

TypeError: '<' not supported between instances of 'NoneType' and 'int'

Cause

https://github.com/markuskiller/textblob-de/blob/8479bde9d66cdb16eeec70b92bd3bfa63cb89ac3/textblob_de/ext/_pattern/text/__init__.py#L1762-L1789

In line 1788, the sorting raises error because the person attribute of the last tense is a None as given:

a = [
    ('past', 1, 'plural', 'indicative', 'imperfective'), 
    ('past', 1, 'plural', 'subjunctive', 'imperfective'), 
    ('past', 3, 'plural', 'indicative', 'imperfective'), 
    ('past', 3, 'plural', 'subjunctive', 'imperfective'), 
    ('past', None, None, 'indicative', 'progressive')
]

Solution

Update the sorting in line 1788 as follows fixes the error:

a = Tenses(sorted(a, key=lambda x: (x[1] is not None, x)))