File tree Expand file tree Collapse file tree 4 files changed +31
-5
lines changed Expand file tree Collapse file tree 4 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ It defines the following items:
42
42
Return the group database entry for the given numeric group ID. :exc: `KeyError `
43
43
is raised if the entry asked for cannot be found.
44
44
45
+ .. deprecated :: 3.6
46
+ Since Python 3.6 the support of non-integer arguments like floats or
47
+ strings in :func: `getgrgid ` is deprecated.
45
48
46
49
.. function :: getgrnam(name)
47
50
Original file line number Diff line number Diff line change @@ -92,5 +92,15 @@ def test_errors(self):
92
92
93
93
self .assertRaises (KeyError , grp .getgrgid , fakegid )
94
94
95
+ def test_noninteger_gid (self ):
96
+ entries = grp .getgrall ()
97
+ if not entries :
98
+ self .skipTest ('no groups' )
99
+ # Choose an existent gid.
100
+ gid = entries [0 ][2 ]
101
+ self .assertWarns (DeprecationWarning , grp .getgrgid , float (gid ))
102
+ self .assertWarns (DeprecationWarning , grp .getgrgid , str (gid ))
103
+
104
+
95
105
if __name__ == "__main__" :
96
106
unittest .main ()
Original file line number Diff line number Diff line change @@ -131,6 +131,8 @@ Core and Builtins
131
131
Library
132
132
-------
133
133
134
+ - Issue #26129: Deprecated accepting non-integers in grp.getgrgid().
135
+
134
136
- Issue #25850: Use cross-compilation by default for 64-bit Windows.
135
137
136
138
- Issue #25822: Add docstrings to the fields of urllib.parse results.
Original file line number Diff line number Diff line change @@ -100,14 +100,25 @@ grp_getgrgid_impl(PyModuleDef *module, PyObject *id)
100
100
gid_t gid ;
101
101
struct group * p ;
102
102
103
- py_int_id = PyNumber_Long ( id );
104
- if (!py_int_id )
103
+ if (! _Py_Gid_Converter ( id , & gid )) {
104
+ if (!PyErr_ExceptionMatches ( PyExc_TypeError )) {
105
105
return NULL ;
106
- if (!_Py_Gid_Converter (py_int_id , & gid )) {
106
+ }
107
+ PyErr_Clear ();
108
+ if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
109
+ "group id must be int, not %.200" ,
110
+ id -> ob_type -> tp_name ) < 0 ) {
111
+ return NULL ;
112
+ }
113
+ py_int_id = PyNumber_Long (id );
114
+ if (!py_int_id )
115
+ return NULL ;
116
+ if (!_Py_Gid_Converter (py_int_id , & gid )) {
117
+ Py_DECREF (py_int_id );
118
+ return NULL ;
119
+ }
107
120
Py_DECREF (py_int_id );
108
- return NULL ;
109
121
}
110
- Py_DECREF (py_int_id );
111
122
112
123
if ((p = getgrgid (gid )) == NULL ) {
113
124
PyObject * gid_obj = _PyLong_FromGid (gid );
You can’t perform that action at this time.
0 commit comments