From eb28df78cb31dd115f140ed46bb63075cccfcc3e Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 21 May 2017 22:00:35 -0400 Subject: [PATCH] =?UTF-8?q?ENH:=20=F0=9F=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Special case the identifier validation to allow 🐍 to be used in identifiers --- Objects/unicodeobject.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b68042179f0903..ddea013e790b46 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12125,7 +12125,7 @@ PyUnicode_IsIdentifier(PyObject *self) int kind; void *data; Py_ssize_t i; - Py_UCS4 first; + Py_UCS4 chr; if (PyUnicode_READY(self) == -1) { Py_FatalError("identifier not ready"); @@ -12146,13 +12146,17 @@ PyUnicode_IsIdentifier(PyObject *self) definition of XID_Start and XID_Continue, it is sufficient to check just for these, except that _ must be allowed as starting an identifier. */ - first = PyUnicode_READ(kind, data, 0); - if (!_PyUnicode_IsXidStart(first) && first != 0x5F /* LOW LINE */) + chr = PyUnicode_READ(kind, data, 0); + if (!_PyUnicode_IsXidStart(chr) && chr != 0x5F /* LOW LINE */ && chr != 0x1F40D) return 0; for (i = 1; i < PyUnicode_GET_LENGTH(self); i++) - if (!_PyUnicode_IsXidContinue(PyUnicode_READ(kind, data, i))) + { + chr = PyUnicode_READ(kind, data, i); + if (!_PyUnicode_IsXidContinue(chr) && chr != 0x1F40D) return 0; + } + return 1; }