Skip to content

Commit 7e95bef

Browse files
committed
Use unicode and stop supporting str8
1 parent fe53713 commit 7e95bef

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

‎Lib/test/test_funcattrs.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ def f(): pass
258258
def test_func_name():
259259
def f(): pass
260260
verify(f.__name__ == "f")
261-
f.__name__ = str8("g")
262-
verify(f.__name__ == str8("g"))
261+
f.__name__ = "g"
262+
verify(f.__name__ == "g")
263263
cantset(f, "__globals__", 1)
264264
cantset(f, "__name__", 1)
265265
# test that you can access func.__name__ in restricted mode

‎Objects/funcobject.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
2929
consts = ((PyCodeObject *)code)->co_consts;
3030
if (PyTuple_Size(consts) >= 1) {
3131
doc = PyTuple_GetItem(consts, 0);
32-
if (!PyString_Check(doc) && !PyUnicode_Check(doc))
32+
if (!PyUnicode_Check(doc))
3333
doc = Py_None;
3434
}
3535
else
@@ -44,7 +44,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
4444
Otherwise, use None.
4545
*/
4646
if (!__name__) {
47-
__name__ = PyString_InternFromString("__name__");
47+
__name__ = PyUnicode_InternFromString("__name__");
4848
if (!__name__) {
4949
Py_DECREF(op);
5050
return NULL;
@@ -297,7 +297,7 @@ func_set_code(PyFunctionObject *op, PyObject *value)
297297
PyErr_Format(PyExc_ValueError,
298298
"%s() requires a code object with %zd free vars,"
299299
" not %zd",
300-
PyString_AsString(op->func_name),
300+
PyUnicode_AsString(op->func_name),
301301
nclosure, nfree);
302302
return -1;
303303
}
@@ -322,7 +322,7 @@ func_set_name(PyFunctionObject *op, PyObject *value)
322322

323323
/* Not legal to del f.func_name or to set it to anything
324324
* other than a string object. */
325-
if (value == NULL || (!PyString_Check(value) && !PyUnicode_Check(value))) {
325+
if (value == NULL || !PyUnicode_Check(value)) {
326326
PyErr_SetString(PyExc_TypeError,
327327
"__name__ must be set to a string object");
328328
return -1;
@@ -482,12 +482,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
482482
&PyDict_Type, &globals,
483483
&name, &defaults, &closure))
484484
return NULL;
485-
if (PyUnicode_Check(name)) {
486-
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
487-
if (name == NULL)
488-
return NULL;
489-
}
490-
if (name != Py_None && !PyString_Check(name)) {
485+
if (name != Py_None && !PyUnicode_Check(name)) {
491486
PyErr_SetString(PyExc_TypeError,
492487
"arg 3 (name) must be None or string");
493488
return NULL;
@@ -573,9 +568,8 @@ func_dealloc(PyFunctionObject *op)
573568
static PyObject*
574569
func_repr(PyFunctionObject *op)
575570
{
576-
return PyUnicode_FromFormat("<function %s at %p>",
577-
PyString_AsString(op->func_name),
578-
op);
571+
return PyUnicode_FromFormat("<function %U at %p>",
572+
op->func_name, op);
579573
}
580574

581575
static int

0 commit comments

Comments
 (0)