summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-15 23:37:13 (GMT)
committerGitHub <noreply@github.com>2020-09-15 23:37:13 (GMT)
commit49917d576a578c8c29b8dbcbd5257c366a53d498 (patch)
tree7f100a76b6d2e5e3a9cf189ba33412aefd1d3f88 /Objects
parent03748837342d45126e71727b400e8fb3d96afc9f (diff)
downloadcpython-49917d576a578c8c29b8dbcbd5257c366a53d498.zip
cpython-49917d576a578c8c29b8dbcbd5257c366a53d498.tar.gz
cpython-49917d576a578c8c29b8dbcbd5257c366a53d498.tar.bz2
bpo-41780: Fix __dir__ of types.GenericAlias (GH-22262)
Automerge-Triggered-By: @gvanrossum (cherry picked from commit 2e87774df1a0eaf2a1fe8cc4d958df60f7125b6e) Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genericaliasobject.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 4d511a2..4f95216 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -487,11 +487,50 @@ ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
alias->origin, alias->args);
}
+static PyObject *
+ga_dir(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+ gaobject *alias = (gaobject *)self;
+ PyObject *dir = PyObject_Dir(alias->origin);
+ if (dir == NULL) {
+ return NULL;
+ }
+
+ PyObject *dir_entry = NULL;
+ for (const char * const *p = attr_exceptions; ; p++) {
+ if (*p == NULL) {
+ break;
+ }
+ else {
+ dir_entry = PyUnicode_FromString(*p);
+ if (dir_entry == NULL) {
+ goto error;
+ }
+ int contains = PySequence_Contains(dir, dir_entry);
+ if (contains < 0) {
+ goto error;
+ }
+ if (contains == 0 && PyList_Append(dir, dir_entry) < 0) {
+ goto error;
+ }
+
+ Py_CLEAR(dir_entry);
+ }
+ }
+ return dir;
+
+error:
+ Py_DECREF(dir);
+ Py_XDECREF(dir_entry);
+ return NULL;
+}
+
static PyMethodDef ga_methods[] = {
{"__mro_entries__", ga_mro_entries, METH_O},
{"__instancecheck__", ga_instancecheck, METH_O},
{"__subclasscheck__", ga_subclasscheck, METH_O},
{"__reduce__", ga_reduce, METH_NOARGS},
+ {"__dir__", ga_dir, METH_NOARGS},
{0}
};