Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3655,6 +3655,9 @@ def test_unpickable(self):
import pickle
self.assertRaises(TypeError, pickle.dumps, entry, filename)

def test_class_getitem(self):
self.assertIs(os.DirEntry[str], os.DirEntry)


class TestScandir(unittest.TestCase):
check_no_resource_warning = support.check_no_resource_warning
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement dummy ``__class_getitem__`` for ``os.DirEntry``.
8 changes: 8 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -12791,6 +12791,13 @@ os_DirEntry___fspath___impl(DirEntry *self)
return self->path;
}

static PyObject *
DirEntry_cls_getitem(PyObject *cls, PyObject *type)
{
Py_INCREF(cls);
return cls;
}

static PyMemberDef DirEntry_members[] = {
{"name", T_OBJECT_EX, offsetof(DirEntry, name), READONLY,
"the entry's base filename, relative to scandir() \"path\" argument"},
Expand All @@ -12808,6 +12815,7 @@ static PyMethodDef DirEntry_methods[] = {
OS_DIRENTRY_STAT_METHODDEF
OS_DIRENTRY_INODE_METHODDEF
OS_DIRENTRY___FSPATH___METHODDEF
{"__class_getitem__", DirEntry_cls_getitem, METH_O|METH_CLASS, NULL},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use Argument Clinic for this (to be consistent with the rest of the code in this module)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if it possible, contextlib also uses argument clinic but they seperated __class_getitem. I thought there is a catch about this but I can try to do this with argument clinic.

{NULL}
};

Expand Down