| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -369,12 +369,13 @@ def _call_with_frames_removed(f, *args, **kwds): | |||
| 369 | 369 | # free vars) | |
| 370 | 370 | # Python 3.4a1 3270 (various tweaks to the __class__ closure) | |
| 371 | 371 | # Python 3.4a1 3280 (remove implicit class argument) | |
| 372 | + # Python 3.4a4 3290 (changes to __qualname__ computation) | ||
| 372 | 373 | # | |
| 373 | 374 | # MAGIC must change whenever the bytecode emitted by the compiler may no | |
| 374 | 375 | # longer be understood by older implementations of the eval loop (usually | |
| 375 | 376 | # due to the addition of new opcodes). | |
| 376 | 377 | ||
| 377 | - MAGIC_NUMBER = (3280).to_bytes(2, 'little') + b'\r\n' | ||
| 378 | + MAGIC_NUMBER = (3290).to_bytes(2, 'little') + b'\r\n' | ||
| 378 | 379 | _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c | |
| 379 | 380 | ||
| 380 | 381 | _PYCACHE = '__pycache__' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4517,6 +4517,11 @@ class X: | |||
| 4517 | 4517 | self.assertRaises(TypeError, type.__dict__['__qualname__'].__set__, | |
| 4518 | 4518 | str, 'Oink') | |
| 4519 | 4519 | ||
| 4520 | + global Y | ||
| 4521 | + class Y: | ||
| 4522 | + pass | ||
| 4523 | + self.assertEqual(Y.__qualname__, 'Y') | ||
| 4524 | + | ||
| 4520 | 4525 | def test_qualname_dict(self): | |
| 4521 | 4526 | ns = {'__qualname__': 'some.name'} | |
| 4522 | 4527 | tp = type('Foo', (), ns) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,9 @@ def global_function(): | |||
| 7 | 7 | def inner_function(): | |
| 8 | 8 | class LocalClass: | |
| 9 | 9 | pass | |
| 10 | + global inner_global_function | ||
| 11 | + def inner_global_function(): | ||
| 12 | + pass | ||
| 10 | 13 | return LocalClass | |
| 11 | 14 | return lambda: inner_function | |
| 12 | 15 | ||
@@ -116,6 +119,7 @@ def test___qualname__(self): | |||
| 116 | 119 | 'global_function.<locals>.inner_function') | |
| 117 | 120 | self.assertEqual(global_function()()().__qualname__, | |
| 118 | 121 | 'global_function.<locals>.inner_function.<locals>.LocalClass') | |
| 122 | + self.assertEqual(inner_global_function.__qualname__, 'inner_global_function') | ||
| 119 | 123 | self.b.__qualname__ = 'c' | |
| 120 | 124 | self.assertEqual(self.b.__qualname__, 'c') | |
| 121 | 125 | self.b.__qualname__ = 'd' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ Projected release date: 2013-10-20 | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #19301: Give classes and functions that are explicitly marked global a | ||
| 14 | + global qualname. | ||
| 15 | + | ||
| 13 | 16 | - Issue #19279: UTF-7 decoder no more produces illegal strings. | |
| 14 | 17 | ||
| 15 | 18 | - Issue #16612: Add "Argument Clinic", a compile-time preprocessor for | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -650,9 +650,10 @@ compiler_exit_scope(struct compiler *c) | |||
| 650 | 650 | } | |
| 651 | 651 | ||
| 652 | 652 | static PyObject * | |
| 653 | - compiler_scope_qualname(struct compiler *c) | ||
| 653 | + compiler_scope_qualname(struct compiler *c, identifier scope_name) | ||
| 654 | 654 | { | |
| 655 | - Py_ssize_t stack_size, i; | ||
| 655 | + Py_ssize_t stack_size; | ||
| 656 | + int global_scope; | ||
| 656 | 657 | _Py_static_string(dot, "."); | |
| 657 | 658 | _Py_static_string(locals, "<locals>"); | |
| 658 | 659 | struct compiler_unit *u; | |
@@ -669,22 +670,41 @@ compiler_scope_qualname(struct compiler *c) | |||
| 669 | 670 | return NULL; | |
| 670 | 671 | ||
| 671 | 672 | stack_size = PyList_GET_SIZE(c->c_stack); | |
| 672 | - for (i = 0; i < stack_size; i++) { | ||
| 673 | - capsule = PyList_GET_ITEM(c->c_stack, i); | ||
| 673 | + global_scope = stack_size <= 1; | ||
| 674 | + if (scope_name != NULL && !global_scope) { | ||
| 675 | + int scope; | ||
| 676 | + PyObject *mangled; | ||
| 677 | + capsule = PyList_GET_ITEM(c->c_stack, stack_size - 1); | ||
| 674 | 678 | u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT); | |
| 675 | 679 | assert(u); | |
| 676 | - if (u->u_scope_type == COMPILER_SCOPE_MODULE) | ||
| 677 | - continue; | ||
| 678 | - if (PyList_Append(seq, u->u_name)) | ||
| 679 | - goto _error; | ||
| 680 | - if (u->u_scope_type == COMPILER_SCOPE_FUNCTION) { | ||
| 681 | - locals_str = _PyUnicode_FromId(&locals); | ||
| 682 | - if (locals_str == NULL) | ||
| 683 | - goto _error; | ||
| 684 | - if (PyList_Append(seq, locals_str)) | ||
| 680 | + mangled = _Py_Mangle(u->u_private, scope_name); | ||
| 681 | + if (!mangled) | ||
| 682 | + return NULL; | ||
| 683 | + scope = PyST_GetScope(u->u_ste, mangled); | ||
| 684 | + Py_DECREF(mangled); | ||
| 685 | + assert(scope != GLOBAL_IMPLICIT); | ||
| 686 | + if (scope == GLOBAL_EXPLICIT) | ||
| 687 | + global_scope = 1; | ||
| 688 | + } | ||
| 689 | + if (!global_scope) { | ||
| 690 | + Py_ssize_t i; | ||
| 691 | + for (i = 1; i < stack_size; i++) { | ||
| 692 | + capsule = PyList_GET_ITEM(c->c_stack, i); | ||
| 693 | + u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT); | ||
| 694 | + assert(u); | ||
| 695 | + assert(u->u_scope_type != COMPILER_SCOPE_MODULE); | ||
| 696 | + if (PyList_Append(seq, u->u_name)) | ||
| 685 | 697 | goto _error; | |
| 698 | + if (u->u_scope_type == COMPILER_SCOPE_FUNCTION) { | ||
| 699 | + locals_str = _PyUnicode_FromId(&locals); | ||
| 700 | + if (locals_str == NULL) | ||
| 701 | + goto _error; | ||
| 702 | + if (PyList_Append(seq, locals_str)) | ||
| 703 | + goto _error; | ||
| 704 | + } | ||
| 686 | 705 | } | |
| 687 | 706 | } | |
| 707 | + | ||
| 688 | 708 | u = c->u; | |
| 689 | 709 | if (PyList_Append(seq, u->u_name)) | |
| 690 | 710 | goto _error; | |
@@ -1649,7 +1669,7 @@ compiler_function(struct compiler *c, stmt_ty s) | |||
| 1649 | 1669 | VISIT_IN_SCOPE(c, stmt, st); | |
| 1650 | 1670 | } | |
| 1651 | 1671 | co = assemble(c, 1); | |
| 1652 | - qualname = compiler_scope_qualname(c); | ||
| 1672 | + qualname = compiler_scope_qualname(c, s->v.FunctionDef.name); | ||
| 1653 | 1673 | compiler_exit_scope(c); | |
| 1654 | 1674 | if (qualname == NULL || co == NULL) { | |
| 1655 | 1675 | Py_XDECREF(qualname); | |
@@ -1722,7 +1742,7 @@ compiler_class(struct compiler *c, stmt_ty s) | |||
| 1722 | 1742 | } | |
| 1723 | 1743 | Py_DECREF(str); | |
| 1724 | 1744 | /* store the __qualname__ */ | |
| 1725 | - str = compiler_scope_qualname(c); | ||
| 1745 | + str = compiler_scope_qualname(c, s->v.ClassDef.name); | ||
| 1726 | 1746 | if (!str) { | |
| 1727 | 1747 | compiler_exit_scope(c); | |
| 1728 | 1748 | return 0; | |
@@ -1862,7 +1882,7 @@ compiler_lambda(struct compiler *c, expr_ty e) | |||
| 1862 | 1882 | ADDOP_IN_SCOPE(c, RETURN_VALUE); | |
| 1863 | 1883 | } | |
| 1864 | 1884 | co = assemble(c, 1); | |
| 1865 | - qualname = compiler_scope_qualname(c); | ||
| 1885 | + qualname = compiler_scope_qualname(c, NULL); | ||
| 1866 | 1886 | compiler_exit_scope(c); | |
| 1867 | 1887 | if (qualname == NULL || co == NULL) | |
| 1868 | 1888 | return 0; | |
@@ -3139,7 +3159,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, identifier name, | |||
| 3139 | 3159 | } | |
| 3140 | 3160 | ||
| 3141 | 3161 | co = assemble(c, 1); | |
| 3142 | - qualname = compiler_scope_qualname(c); | ||
| 3162 | + qualname = compiler_scope_qualname(c, NULL); | ||
| 3143 | 3163 | compiler_exit_scope(c); | |
| 3144 | 3164 | if (qualname == NULL || co == NULL) | |
| 3145 | 3165 | goto error; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments