Skip to content

Cannot have python keyword in route name #4691

Closed
@jrozentur

Description

🐞 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

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions