[issue17447] str.identifier shouldn't accept Python keywords
Ezio Melotti added the comment: IMHO str.isidentifier() should not return False for Python keywords, since it's often used in contexts where Python keywords would otherwise be valid. A keyword arg to exclude keywords could be added though, assuming there are enough use cases. -- nosy: +ezio.melotti type: behavior - enhancement versions: -Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
Roundup Robot added the comment: New changeset a7fe48dfbfe9 by Raymond Hettinger in branch '3.3': Issue 17447: Clarify that str.isidentifier doesn't check for reserved keywords. http://hg.python.org/cpython/rev/a7fe48dfbfe9 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
Raymond Hettinger added the comment: I've added a clarification to the docs. Closing this report as invalid. -- resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
New submission from Raymond Hettinger: 'def'.isidentifier() True -- components: Interpreter Core messages: 184389 nosy: rhettinger priority: normal severity: normal status: open title: str.identifier shouldn't accept Python keywords type: behavior versions: Python 3.2, Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
Florent Xicluna added the comment: According to the documentation, the reserved words are classified as identifiers: http://docs.python.org/3/reference/lexical_analysis.html#keywords There's an easy workaround: from keyword import iskeyword def is_valid_identifier(s): ... return s.isidentifier() and not iskeyword(s) ... is_valid_identifier('def') False -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
R. David Murray added the comment: Or maybe 'is_usable_identifier' :) -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
Serhiy Storchaka added the comment: Hmm. I were going to use this method for re's named group (see issue14462). There is a possibility that some third-party code uses it for checking on general Unicode-aware identifiers. The language specifification says that keywords is a subset of identifiers. However in most places in stdlib (collections.namedtuple, unittest.mock, inspect.Parameter) is_usable_identifier() should be used instead of isidentifier(). -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17447] str.identifier shouldn't accept Python keywords
Matthew Barnett added the comment: I already use it in the regex module for named groups. I don't think it would ever be a problem in practice because the names are invariably handled as strings. -- nosy: +mrabarnett ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17447 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com