File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
PyQt6/core/auto_generated Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ geometry and a list of field/values attributes.
40
40
QgsAttributes attributes = sipCpp->attributes();
41
41
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
42
42
sipRes = PyObject_GetIter( attrs );
43
+ // PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
44
+ // so that the garbage collector will delete attrs when the iterator is deleted
45
+ Py_DECREF( attrs );
43
46
%End
44
47
45
48
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ geometry and a list of field/values attributes.
40
40
QgsAttributes attributes = sipCpp->attributes();
41
41
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
42
42
sipRes = PyObject_GetIter( attrs );
43
+ // PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
44
+ // so that the garbage collector will delete attrs when the iterator is deleted
45
+ Py_DECREF( attrs );
43
46
%End
44
47
45
48
SIP_PYOBJECT __getitem__( int key ) /HoldGIL/;
Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ class CORE_EXPORT QgsFeature
76
76
QgsAttributes attributes = sipCpp->attributes ();
77
77
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
78
78
sipRes = PyObject_GetIter( attrs );
79
+ // PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
80
+ // so that the garbage collector will delete attrs when the iterator is deleted
81
+ Py_DECREF ( attrs );
79
82
% End
80
83
#endif
81
84
Original file line number Diff line number Diff line change @@ -320,6 +320,39 @@ def test_FeatureCount(self):
320
320
myCount = myLayer .featureCount ()
321
321
self .assertEqual (myCount , 6 )
322
322
323
+ def test_attribute_iteration (self ):
324
+ layer = QgsVectorLayer (
325
+ self .get_test_data_path ("lines.shp" ).as_posix (), "Lines" , "ogr"
326
+ )
327
+ self .assertTrue (layer .isValid ())
328
+ all_attrs = [
329
+ [attr for attr in feat .attributes ()] for feat in layer .getFeatures ()
330
+ ]
331
+ self .assertCountEqual (
332
+ all_attrs ,
333
+ [
334
+ ["Highway" , 1.0 ],
335
+ ["Highway" , 1.0 ],
336
+ ["Arterial" , 2.0 ],
337
+ ["Arterial" , 2.0 ],
338
+ ["Arterial" , 2.0 ],
339
+ ["Arterial" , 2.0 ],
340
+ ],
341
+ )
342
+
343
+ all_attrs = [[attr for attr in feat ] for feat in layer .getFeatures ()]
344
+ self .assertCountEqual (
345
+ all_attrs ,
346
+ [
347
+ ["Highway" , 1.0 ],
348
+ ["Highway" , 1.0 ],
349
+ ["Arterial" , 2.0 ],
350
+ ["Arterial" , 2.0 ],
351
+ ["Arterial" , 2.0 ],
352
+ ["Arterial" , 2.0 ],
353
+ ],
354
+ )
355
+
323
356
# undo stack
324
357
def testUndoStack (self ):
325
358
layer = createLayerWithOnePoint ()
You can’t perform that action at this time.
0 commit comments