misc: use keyword.kwlist to get list of reserved keywords (#76195)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-04-04 08:53:08 +02:00
parent 097969e58c
commit ad54651415
1 changed files with 3 additions and 41 deletions

View File

@ -24,6 +24,7 @@ import html
import io
import itertools
import json
import keyword
import mimetypes
import os
import random
@ -1692,47 +1693,8 @@ class VarnameWidget(ValidatedStringWidget):
# "native" id/text keys in datasources; forbid "status" to avoid status
# filtering being diverted to a form field.
# And forbid all reserved Python keywords so varnames can be used in
# dotted expressions (form.var.plop). (keyword.kwlist in Python 3.9)
if self.value in (
'id',
'text',
'status',
'and',
'as',
'assert',
'async',
'await',
'break',
'class',
'continue',
'def',
'del',
'elif',
'else',
'except',
'False',
'finally',
'for',
'from',
'global',
'if',
'import',
'in',
'is',
'lambda',
'None',
'nonlocal',
'not',
'or',
'pass',
'raise',
'return',
'True',
'try',
'while',
'with',
'yield',
):
# dotted expressions (form.var.plop).
if self.value in ('id', 'text', 'status') + tuple(keyword.kwlist):
self.error = _('this value is reserved for internal use.')