klen / muffin

Muffin is a fast, simple and asyncronous web-framework for Python 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reverse url constructing broken on Python 3.5

MarSoft opened this issue · comments

Which is the preferred method to construct URL for given endpoint?
When I try method documented for aiohttp, it fails with an exception:

In [99]: app.router['itempage'].url()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-99-2c61d7afd253> in <module>()
----> 1 app.router['itempage'].url()

/home/mars/env/lib/python3.5/site-packages/muffin/urls.py in url(self, query, *subgroups, **groups)
     51             if k0 in groups_
     52         })
---> 53         url = ''.join(str(val) for val in Traverser(parsed, subgroups))
     54         return self._append_query(url, query)
     55

/home/mars/env/lib/python3.5/site-packages/muffin/urls.py in <genexpr>(.0)
     51             if k0 in groups_
     52         })
---> 53         url = ''.join(str(val) for val in Traverser(parsed, subgroups))
     54         return self._append_query(url, query)
     55

/home/mars/env/lib/python3.5/site-packages/muffin/urls.py in __iter__(self)
    156         """Iterate builded parts."""
    157         for state, value in self.parsed:
--> 158             yield from getattr(self, "state_" + state, self.state_default)(value)
    159
    160     def __next__(self):

TypeError: Can't convert '_NamedIntConstant' object to str implicitly

I use Python 3.5, and seems that it changed structure of re.sre_parse module (which is anyway internal) so now this code doesn't work. Does it require rewriting? Of course we could use something like str(state).lower instead of state, but it looks like a hack for me...

Rechecked, and seems that related tests are failing on Python 3.5 while they succeed on Python 3.4.

Also @klen can you add Python 3.5 checks on Travis? Because this regression was caught successfully by py.test on python 3.5.
UPD: added it myself, commit is within the same pull request.

Resolved by that pull request.