jpvanhal / inflection

A port of Ruby on Rails' inflector to Python
https://inflection.readthedocs.io
MIT License
495 stars 61 forks source link

pluralize() throws a type error for UNCOUNTABLES being NoneType #9

Open archit opened 8 years ago

archit commented 8 years ago

if I do a manual python shell session, I can pluralize() just fine. Similarly my application code when I run it, runs without any errors, exceptions. However when I run my unit tests for code that uses inflection.pluralize() I get the error

word = 'network'

    def pluralize(word):
        """
        Return the plural form of a word.

        Examples::

            >>> pluralize("post")
            "posts"
            >>> pluralize("octopus")
            "octopi"
            >>> pluralize("sheep")
            "sheep"
            >>> pluralize("CamelOctopus")
            "CamelOctopi"

        """
>       if not word or word.lower() in UNCOUNTABLES:
E       TypeError: argument of type 'NoneType' is not iterable

/usr/local/lib/python2.7/dist-packages/inflection.py:297: TypeError
3 failed, 50 passed in 0.14 seconds

When I run my tests using py.test --pdb, I'm unable to print any value for UNCOUNTABLES

word = 'networkTopology'

    def pluralize(word):
        """
        Return the plural form of a word.

        Examples::

            >>> pluralize("post")
            "posts"
            >>> pluralize("octopus")
            "octopi"
            >>> pluralize("sheep")
            "sheep"
            >>> pluralize("CamelOctopus")
            "CamelOctopi"

        """
>       if not word or word.lower() in UNCOUNTABLES:
E       TypeError: argument of type 'NoneType' is not iterable

/usr/local/lib/python2.7/dist-packages/inflection.py:297: TypeError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /usr/local/lib/python2.7/dist-packages/inflection.py(297)pluralize()
-> if not word or word.lower() in UNCOUNTABLES:
(Pdb) UNCOUNTABLES
(Pdb) list
292             "sheep"
293             >>> pluralize("CamelOctopus")
294             "CamelOctopi"
295     
296         """
297  ->     if not word or word.lower() in UNCOUNTABLES:
298             return word
299         else:
300             for rule, replacement in PLURALS:
301                 if re.search(rule, word):
302                     return re.sub(rule, replacement, word)
(Pdb) 

I'm using inflection==0.3.1

archit commented 8 years ago

Just an update, for a work around, I threw in from inflection import UNCOUNTABLES in my tests/__init__.py

jpvanhal commented 8 years ago

That seems really strange. Can you post minimal code to reproduce this?