Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot have python keyword in route nameΒ #4691

@jrozentur

Description

@jrozentur

🐞 Describe the bug

This code is rejected with 'Incorrect route name':

@app_routes.get('/result/', name='check-for-result')
async def result(request):

This is because 'for' is a keyword, and the check rejects any keywords for some strange reason:
in https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_urldispatcher.py#L982

parts = self.NAME_SPLIT_RE.split(name)
for part in parts:
      if not part.isidentifier() or keyword.iskeyword(part):
           raise ValueError

I think the intention was to have:

if not (part.isidentifier() or keyword.iskeyword(part))

πŸ’‘ To Reproduce

πŸ’‘ Expected behavior

Should accept route names containing python keywords

πŸ“‹ Logs/tracebacks

πŸ“‹ Your version of the Python

$ python --version
Python 3.7.4

πŸ“‹ Your version of the aiohttp/yarl/multidict distributions

$ python -m pip show aiohttp
Version: 3.6.2
$ python -m pip show multidict
Version: 4.7.5
$ python -m pip show yarl
Version: 1.3.0

πŸ“‹ Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpr-availablereproducer: missingThis PR or issue lacks code, which reproduce the problem described or clearly understandable STRserver

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions