diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 98323112972..ac006a95cbf 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -1272,7 +1272,7 @@ def InitMapDisplay(self): # initialize column sorter self.itemDataMap = self.mapcoordlist ncols = self.list.GetColumnCount() - ColumnSorterMixin.__init__(self, ncols) + ColumnSorterMixin(self, ncols) # init to ascending sort on first click self._colSortFlag = [1] * ncols diff --git a/gui/wxpython/gmodeler/canvas.py b/gui/wxpython/gmodeler/canvas.py index ab49ab770d1..7c604ec6624 100644 --- a/gui/wxpython/gmodeler/canvas.py +++ b/gui/wxpython/gmodeler/canvas.py @@ -85,10 +85,10 @@ def RemoveShapes(self, shapes): remList, upList = self.parent.GetModel().RemoveItem(shape) shape.Select(False) diagram.RemoveShape(shape) - shape.__del__() + shape.__del__() # noqa: PLC2801, C2801 for item in remList: diagram.RemoveShape(item) - item.__del__() + item.__del__() # noqa: PLC2801, C2801 for item in upList: item.Update() diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index 4a587230fa9..b243f0beb5c 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -1577,7 +1577,7 @@ def _defineShape(self, width, height, x, y): :param width, height: dimension of the shape :param x, y: position of the shape """ - ogl.EllipseShape.__init__(self, width, height) + ogl.EllipseShape(self, width, height) if self.parent.GetCanvas(): self.SetCanvas(self.parent.GetCanvas()) @@ -1592,7 +1592,7 @@ def _defineShape(self, width, height, x, y): :param width, height: dimension of the shape :param x, y: position of the shape """ - ogl.CompositeShape.__init__(self) + ogl.CompositeShape(self) if self.parent.GetCanvas(): self.SetCanvas(self.parent.GetCanvas()) diff --git a/gui/wxpython/gmodeler/panels.py b/gui/wxpython/gmodeler/panels.py index 6d6bff45387..300220b9f7c 100644 --- a/gui/wxpython/gmodeler/panels.py +++ b/gui/wxpython/gmodeler/panels.py @@ -542,7 +542,7 @@ def GetOptData(self, dcmd, layer, params, propwin): remList, upList = self.model.RemoveItem(data, layer) for item in remList: self.canvas.diagram.RemoveShape(item) - item.__del__() + item.__del__() # noqa: PLC2801, C2801 for item in upList: item.Update() diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 968e6c50b7d..4aec0eeba5e 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -1257,7 +1257,7 @@ def InitMapDisplay(self): # initialize column sorter self.itemDataMap = self.mapcoordlist ncols = self.list.GetColumnCount() - ColumnSorterMixin.__init__(self, ncols) + ColumnSorterMixin(self, ncols) # init to ascending sort on first click self._colSortFlag = [1] * ncols diff --git a/gui/wxpython/mapdisp/main.py b/gui/wxpython/mapdisp/main.py index 5bef25ad128..1e94d3d8ba2 100644 --- a/gui/wxpython/mapdisp/main.py +++ b/gui/wxpython/mapdisp/main.py @@ -370,7 +370,7 @@ def __next__(self): return result def next(self): - return self.__next__() + return next(self) def GetSelectedLayers(self, checkedOnly=True): # hidden and selected vs checked and selected diff --git a/gui/wxpython/photo2image/ip2i_manager.py b/gui/wxpython/photo2image/ip2i_manager.py index 042053b65e2..2a9ae19d26a 100644 --- a/gui/wxpython/photo2image/ip2i_manager.py +++ b/gui/wxpython/photo2image/ip2i_manager.py @@ -625,7 +625,7 @@ def InitMapDisplay(self): # initialize column sorter self.itemDataMap = self.mapcoordlist ncols = self.list.GetColumnCount() - ColumnSorterMixin.__init__(self, ncols) + ColumnSorterMixin(self, ncols) # init to ascending sort on first click self._colSortFlag = [1] * ncols diff --git a/gui/wxpython/tplot/frame.py b/gui/wxpython/tplot/frame.py index e15e6584808..62147f54ad6 100755 --- a/gui/wxpython/tplot/frame.py +++ b/gui/wxpython/tplot/frame.py @@ -140,7 +140,10 @@ def onClose(self, evt): if self._giface.GetMapDisplay(): self.coorval.OnClose() self.cats.OnClose() - self.__del__() + + # __del__() and del keyword seem to have differences, + # how can self.Destroy(), called after del, work otherwise + self.__del__() # noqa: PLC2801, C2801 self.Destroy() def _layout(self): diff --git a/pyproject.toml b/pyproject.toml index 930c538049b..eb866cb0e08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -158,7 +158,6 @@ ignore = [ "PLC0415", # import-outside-top-level "PLC1901", # compare-to-empty-string "PLC2701", # import-private-name - "PLC2801", # unnecessary-dunder-call "PLE0704", # misplaced-bare-raise "PLR0904", # too-many-public-methods "PLR0911", # too-many-return-statements diff --git a/python/grass/gunittest/utils.py b/python/grass/gunittest/utils.py index 082366cacaf..c1afea3d5ad 100644 --- a/python/grass/gunittest/utils.py +++ b/python/grass/gunittest/utils.py @@ -76,7 +76,7 @@ def safe_repr(obj, short=False): try: result = repr(obj) except Exception: - result = object.__repr__(obj) + result = object.__repr__(obj) # noqa: PLC2801 if not short or len(result) < _MAX_LENGTH: return result return result[:_MAX_LENGTH] + " [truncated]..." diff --git a/python/grass/pygrass/gis/region.py b/python/grass/pygrass/gis/region.py index 0f736978026..98c75a15631 100644 --- a/python/grass/pygrass/gis/region.py +++ b/python/grass/pygrass/gis/region.py @@ -370,7 +370,7 @@ def keys(self): def items(self): """Return a list of tuple with key and value.""" - return [(k, self.__getattribute__(k)) for k in self.keys()] + return [(k, getattr(self, k)) for k in self.keys()] # ----------METHODS---------- def zoom(self, raster_name): diff --git a/python/grass/pygrass/modules/interface/typedict.py b/python/grass/pygrass/modules/interface/typedict.py index c8fdeb48a76..fb3ddb368eb 100644 --- a/python/grass/pygrass/modules/interface/typedict.py +++ b/python/grass/pygrass/modules/interface/typedict.py @@ -64,6 +64,6 @@ def __reduce__(self): def used(self): key_dict = {} for key in self: - if self.__getattr__(key): - key_dict[key] = self.__getattr__(key) + if getattr(self, key): + key_dict[key] = getattr(self, key) return key_dict diff --git a/python/grass/pygrass/raster/abstract.py b/python/grass/pygrass/raster/abstract.py index 616964d8f7b..edea42e7bdd 100644 --- a/python/grass/pygrass/raster/abstract.py +++ b/python/grass/pygrass/raster/abstract.py @@ -247,10 +247,10 @@ def keys(self): ] def items(self): - return [(k, self.__getattribute__(k)) for k in self.keys()] + return [(k, getattr(self, k)) for k in self.keys()] def __iter__(self): - return ((k, self.__getattribute__(k)) for k in self.keys()) + return ((k, getattr(self, k)) for k in self.keys()) def _repr_html_(self): return dict2html(dict(self.items()), keys=self.keys(), border="1", kdec="b") diff --git a/python/grass/pygrass/raster/category.py b/python/grass/pygrass/raster/category.py index 0a5e42093ae..00381f91130 100644 --- a/python/grass/pygrass/raster/category.py +++ b/python/grass/pygrass/raster/category.py @@ -196,13 +196,13 @@ def __del__(self): libraster.Rast_free_cats(ctypes.byref(self.c_cats)) def get_cat(self, index): - return self.__getitem__(index) + return self[index] def set_cat(self, index, value): if index is None: self.append(value) - elif index < self.__len__(): - self.__setitem__(index, value) + elif index < (len(self)): + self[index] = value else: raise TypeError("Index outside range.") @@ -221,7 +221,7 @@ def _write_cats(self): # reset only the C struct libraster.Rast_init_cats("", ctypes.byref(self.c_cats)) # write to the c struct - for cat in self.__iter__(): + for cat in iter(self): label, min_cat, max_cat = cat if max_cat is None: max_cat = min_cat @@ -273,7 +273,7 @@ def copy(self, category): self._read_cats() def ncats(self): - return self.__len__() + return len(self) def set_cats_fmt(self, fmt, m1, a1, m2, a2): """Not implemented yet. @@ -327,7 +327,7 @@ def write_rules(self, filename, sep=":"): :param str sep: the separator used to divide values and category """ cats = [] - for cat in self.__iter__(): + for cat in iter(self): if cat[-1] is None: cat = cat[:-1] cats.append(sep.join([str(i) for i in cat])) diff --git a/python/grass/pygrass/vector/__init__.py b/python/grass/pygrass/vector/__init__.py index 7869b1a29b5..6f29a167b2e 100644 --- a/python/grass/pygrass/vector/__init__.py +++ b/python/grass/pygrass/vector/__init__.py @@ -108,7 +108,7 @@ def __next__(self): @must_be_open def next(self): - return self.__next__() + return next(self) @must_be_open def rewind(self): diff --git a/python/grass/pygrass/vector/basic.py b/python/grass/pygrass/vector/basic.py index 1ce2dccedd8..079f7ac829f 100644 --- a/python/grass/pygrass/vector/basic.py +++ b/python/grass/pygrass/vector/basic.py @@ -137,7 +137,7 @@ def contains(self, point): ) def items(self): - return [(k, self.__getattribute__(k)) for k in self.keys()] + return [(k, getattr(self, k)) for k in self.keys()] def nsewtb(self, tb=True): """Return a list of values from bounding box @@ -215,7 +215,7 @@ def append(self, box): 3 """ - indx = self.__len__() + indx = len(self) libvect.Vect_boxlist_append(self.c_boxlist, indx, box.c_bbox) # def extend(self, boxlist): diff --git a/python/grass/pygrass/vector/geometry.py b/python/grass/pygrass/vector/geometry.py index bc6ad32f10a..1c5d378e6ef 100644 --- a/python/grass/pygrass/vector/geometry.py +++ b/python/grass/pygrass/vector/geometry.py @@ -958,7 +958,7 @@ def pop(self, indx): indx += self.c_points.contents.n_points if indx >= self.c_points.contents.n_points: raise IndexError("Index out of range") - pnt = self.__getitem__(indx) + pnt = self[indx] libvect.Vect_line_delete_point(self.c_points, indx) return pnt @@ -1028,7 +1028,7 @@ def remove(self, pnt): .. """ - for indx, point in enumerate(self.__iter__()): + for indx, point in enumerate(iter(self)): if pnt == point: libvect.Vect_line_delete_point(self.c_points, indx) return @@ -1086,7 +1086,7 @@ def to_list(self): .. """ - return [pnt.coords() for pnt in self.__iter__()] + return [pnt.coords() for pnt in iter(self)] def to_array(self): """Return an array of coordinates. :: @@ -1112,10 +1112,7 @@ def to_wkt_p(self): .. """ return "LINESTRING(%s)" % ", ".join( - [ - " ".join(["%f" % coord for coord in pnt.coords()]) - for pnt in self.__iter__() - ] + [" ".join(["%f" % coord for coord in pnt.coords()]) for pnt in iter(self)] ) def from_wkt(self, wkt): @@ -1592,7 +1589,7 @@ def isles_ids(self): """Return the id of isles""" return [ libvect.Vect_get_area_isle(self.c_mapinfo, self.area_id, i) - for i in range(self.__len__()) + for i in range(len(self)) ] @mapinfo_must_be_set diff --git a/python/grass/pygrass/vector/table.py b/python/grass/pygrass/vector/table.py index dec3ffbba08..4b7e99c0a83 100644 --- a/python/grass/pygrass/vector/table.py +++ b/python/grass/pygrass/vector/table.py @@ -297,7 +297,7 @@ def update_odict(self): [ "?", ] - * self.__len__() + * (len(self)) ) kv = ",".join(["%s=?" % k for k in self.odict.keys() if k != self.key]) where = "%s=?" % self.key diff --git a/python/grass/pygrass/vector/testsuite/test_geometry_attrs.py b/python/grass/pygrass/vector/testsuite/test_geometry_attrs.py index 4c17ef03d4c..356a55ec4d7 100644 --- a/python/grass/pygrass/vector/testsuite/test_geometry_attrs.py +++ b/python/grass/pygrass/vector/testsuite/test_geometry_attrs.py @@ -60,11 +60,11 @@ def test_setitem(self): newvalue = 100.0 newpairs = ("setitem_point_2", 1000.0) - self.attrs.__setitem__("name", newname) + self.attrs.__setitem__("name", newname) # noqa: PLC2801 self.assertEqual(self.attrs["name"], newname) - self.attrs.__setitem__("value", newvalue) + self.attrs.__setitem__("value", newvalue) # noqa: PLC2801 self.assertEqual(self.attrs["value"], newvalue) - self.attrs.__setitem__(("name", "value"), newpairs) + self.attrs.__setitem__(("name", "value"), newpairs) # noqa: PLC2801 self.assertEqual(self.attrs["name", "value"], newpairs)