Skip to content

Commit

Permalink
style: Fix if-exp-instead-of-or-operator (FURB110) (OSGeo#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Jul 11, 2024
1 parent c9a1a17 commit a3543cd
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 68 deletions.
4 changes: 2 additions & 2 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def AppendNode(self, parent, **kwargs):
def SearchNodes(self, parent=None, **kwargs):
"""Search nodes according to specified attributes."""
nodes = []
parent = parent if parent else self.root
parent = parent or self.root
self._searchNodes(node=parent, foundNodes=nodes, **kwargs)
return nodes

Expand Down Expand Up @@ -291,7 +291,7 @@ class ModuleNode(DictNode):

def __init__(self, label=None, data=None):
super().__init__(data=data)
self._label = label if label else ""
self._label = label or ""
if not data:
self.data = {}

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __init__(self, data=None):
def label(self):
data = self.data
if data["type"] == "mapset":
owner = data["owner"] if data["owner"] else _("name unknown")
owner = data["owner"] or _("name unknown")
if data["current"]:
return _("{name} (current)").format(**data)
elif data["is_different_owner"] and data["lock"]:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,7 @@ def __init__(

label = StaticText(self, label=message)
sizer.Add(label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=10)
hyperlinkLabel = hyperlinkLabel if hyperlinkLabel else hyperlink
hyperlinkLabel = hyperlinkLabel or hyperlink
hyperlinkCtrl = HyperlinkCtrl(
self,
id=wx.ID_ANY,
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _initHistoryModel(self):
data={
"type": COMMAND,
"name": entry["command"].strip(),
"timestamp": timestamp if timestamp else None,
"timestamp": timestamp or None,
"status": status,
},
)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/rdigit/g.gui.rdigit.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(
self._mapObj = self.GetMap()

# load raster map
self._addLayer(name=new_map if new_map else edit_map)
self._addLayer(name=new_map or edit_map)

# switch toolbar
self.AddToolbar("rdigit", fixed=True)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/startup/guiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def can_switch_mapset_interactive(guiparent, grassdb, location, mapset):

if is_mapset_locked(mapset_path):
info = get_mapset_lock_info(mapset_path)
user = info["owner"] if info["owner"] else _("unknown")
user = info["owner"] or _("unknown")
lockpath = info["lockpath"]
timestamp = info["timestamp"]

Expand Down
2 changes: 1 addition & 1 deletion man/parser_standard_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _repr_html_(self):
)
args = parser.parse_args()

cfile = args.text if args.text else urlopen(args.url, proxies=None)
cfile = args.text or urlopen(args.url, proxies=None)

options = OptTable(parse_options(cfile.readlines(), startswith=args.startswith))
outform = args.format
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ ignore = [
"FURB101", # read-whole-file
"FURB103", # write-whole-file.
"FURB105", # print-empty-string
"FURB110", # if-exp-instead-of-or-operator
"FURB116", # f-string-number-format
"FURB116", # f-string-number-format
"FURB118", # reimplemented-operator
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/modules/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def __init__(
self.height = height
self.overlap = overlap
self.processes = processes
self.region = region if region else Region()
self.region = region or Region()
self.start_row = start_row
self.start_col = start_col
self.out_prefix = out_prefix
Expand Down
6 changes: 3 additions & 3 deletions python/grass/pygrass/modules/grid/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def split_region_in_overlapping_tiles(region=None, width=100, height=100, overla
[[Bbox(1350.0, 640.0, 1010.0, 0.0), Bbox(1350.0, 640.0, 1500.0, 990.0)],
[Bbox(660.0, 0.0, 1010.0, 0.0), Bbox(660.0, 0.0, 1500.0, 990.0)]]
"""
reg = region if region else Region()
reg = region or Region()
ncols = (reg.cols + width - 1) // width
nrows = (reg.rows + height - 1) // height
box_list = []
Expand All @@ -118,7 +118,7 @@ def split_region_tiles(region=None, width=100, height=100):
:param height: the width of tiles
:type height: int
"""
reg = region if region else Region()
reg = region or Region()
ncols = (reg.cols + width - 1) // width
nrows = (reg.rows + height - 1) // height
box_list = []
Expand All @@ -142,7 +142,7 @@ def get_overlap_region_tiles(region=None, width=100, height=100, overlap=0):
:param overlap: the value of overlap between tiles
:type overlap: int
"""
reg = region if region else Region()
reg = region or Region()
ncols = (reg.cols + width - 1) // width
nrows = (reg.rows + height - 1) // height
box_list = []
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/modules/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MetaModule:

def __init__(self, prefix, cls=None):
self.prefix = prefix
self.cls = cls if cls else Module
self.cls = cls or Module

def __dir__(self):
return [
Expand Down
8 changes: 4 additions & 4 deletions python/grass/pygrass/raster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def open(self, mode=None, mtype=None, overwrite=None):
* self._rows and self._cols
"""
self.mode = mode if mode else self.mode
self.mtype = mtype if mtype else self.mtype
self.mode = mode or self.mode
self.mtype = mtype or self.mtype
self.overwrite = overwrite if overwrite is not None else self.overwrite

if self.mode == "r":
Expand Down Expand Up @@ -509,8 +509,8 @@ def open(self, mode=None, mtype=None, overwrite=None):
self._rows = libraster.Rast_window_rows()
self._cols = libraster.Rast_window_cols()

self.mode = mode if mode else self.mode
self.mtype = mtype if mtype else self.mtype
self.mode = mode or self.mode
self.mtype = mtype or self.mtype
self.overwrite = overwrite if overwrite is not None else self.overwrite

if self.exist():
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/raster/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def exist(self):
if self.name:
if self.mapset == "":
mapset = utils.get_mapset_raster(self.name, self.mapset)
self.mapset = mapset if mapset else ""
self.mapset = mapset or ""
return bool(mapset)
return bool(utils.get_mapset_raster(self.name, self.mapset))
else:
Expand Down
6 changes: 3 additions & 3 deletions python/grass/pygrass/shell/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def dict2html(
def fun(x):
return x

keys = keys if keys else sorted(dic.keys())
keys = keys or sorted(dic.keys())
header = "<table border=%r>" % border if border else "<table>"
kd = "<%s>%s</%s>" % (kdec, kfmt, kdec) if kdec else kfmt
vd = "<%s>%s</%s>" % (vdec, vfmt, vdec) if vdec else vfmt
kfun = kfun if kfun else fun
vfun = vfun if vfun else fun
kfun = kfun or fun
vfun = vfun or fun
content = [dcont.format(key=kd % kfun(k), value=vd % vfun(dic[k])) for k in keys]
return "\n".join(
[
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def r_export(rast, output="", fmt="png", **kargs):
from grass.pygrass.modules import Module

if rast.exist():
output = output if output else "%s_%s.%s" % (rast.name, rast.mapset, fmt)
output = output or "%s_%s.%s" % (rast.name, rast.mapset, fmt)
Module(
"r.out.%s" % fmt,
input=rast.fullname(),
Expand Down
8 changes: 4 additions & 4 deletions python/grass/pygrass/vector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ def __getitem__(self, key):
return [
self.read(indx)
for indx in range(
key.start if key.start else 1,
key.stop if key.stop else len(self),
key.step if key.step else 1,
key.start or 1,
key.stop or len(self),
key.step or 1,
)
]
elif isinstance(key, int):
Expand Down Expand Up @@ -509,7 +509,7 @@ def cat(self, cat_id, vtype, layer=None, generator=False, geo=None):
ilist = Ilist()
libvect.Vect_cidx_find_all(
self.c_mapinfo,
layer if layer else self.layer,
layer or self.layer,
Obj.gtype,
cat_id,
ilist.c_ilist,
Expand Down
8 changes: 4 additions & 4 deletions python/grass/pygrass/vector/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def exist(self):
if self.name:
if self.mapset == "":
mapset = utils.get_mapset_vector(self.name, self.mapset)
self.mapset = mapset if mapset else ""
self.mapset = mapset or ""
return bool(mapset)
return bool(utils.get_mapset_vector(self.name, self.mapset))
else:
Expand Down Expand Up @@ -358,7 +358,7 @@ def open(
See more examples in the documentation of the ``read`` and ``write``
methods
"""
self.mode = mode if mode else self.mode
self.mode = mode or self.mode
with_z = libvect.WITH_Z if with_z else libvect.WITHOUT_Z
# check if map exists or not
if not self.exist() and self.mode != "w":
Expand Down Expand Up @@ -396,8 +396,8 @@ def open(
# create a link
link = Link(
layer,
link_name if link_name else self.name,
tab_name if tab_name else self.name,
link_name or self.name,
tab_name or self.name,
link_key,
link_db,
link_driver,
Expand Down
10 changes: 3 additions & 7 deletions python/grass/pygrass/vector/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def contains(self, point):
"""
return bool(
libvect.Vect_point_in_box(
point.x, point.y, point.z if point.z else 0, self.c_bbox
)
libvect.Vect_point_in_box(point.x, point.y, point.z or 0, self.c_bbox)
)

def items(self):
Expand Down Expand Up @@ -424,7 +422,7 @@ def n_cats(self):
return self.c_cats.contents.n_cats

def __init__(self, c_cats=None):
self.c_cats = c_cats if c_cats else ctypes.pointer(libvect.line_cats())
self.c_cats = c_cats or ctypes.pointer(libvect.line_cats())

def reset(self):
"""Reset the C cats struct from previous values."""
Expand Down Expand Up @@ -541,9 +539,7 @@ def max(self):
return [max_values[i] for i in range(self.n_ranges)]

def __init__(self, c_cat_list=None):
self.c_cat_list = (
c_cat_list if c_cat_list else ctypes.pointer(libvect.cat_list())
)
self.c_cat_list = c_cat_list or ctypes.pointer(libvect.cat_list())

def from_string(self, string):
"""Converts string of categories and cat ranges separated by commas
Expand Down
8 changes: 4 additions & 4 deletions python/grass/pygrass/vector/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def node(self, point, maxdist):
self.c_mapinfo,
point.x,
point.y,
point.z if point.z else 0,
point.z or 0,
float(maxdist),
int(not point.is2D),
)
Expand Down Expand Up @@ -166,7 +166,7 @@ def geo(self, point, maxdist, type="all", exclude=0):
self.c_mapinfo,
point.x,
point.y,
point.z if point.z else 0,
point.z or 0,
self.vtype[type],
float(maxdist),
int(not point.is2D),
Expand Down Expand Up @@ -257,7 +257,7 @@ def geos(self, point, maxdist, type="all", exclude=None):
self.c_mapinfo,
point.x,
point.y,
point.z if point.z else 0,
point.z or 0,
self.vtype[type],
float(maxdist),
int(not point.is2D),
Expand Down Expand Up @@ -586,7 +586,7 @@ def areas(self, bbox, boxlist=None, bboxlist_only=False):
>>> test_vect.close()
"""
boxlist = boxlist if boxlist else BoxList()
boxlist = boxlist or BoxList()
if libvect.Vect_select_areas_by_box(
self.c_mapinfo, bbox.c_bbox, boxlist.c_boxlist
):
Expand Down
20 changes: 10 additions & 10 deletions python/grass/pygrass/vector/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def bbox(self, bbox=None):
..
"""
bbox = bbox if bbox else Bbox()
bbox = bbox or Bbox()
libvect.Vect_line_box(self.c_points, bbox.c_bbox)
return bbox

Expand Down Expand Up @@ -1376,7 +1376,7 @@ def __repr__(self):
def _centroid(self, side, idonly=False):
if side > 0:
v_id = libvect.Vect_get_area_centroid(self.c_mapinfo, side)
v_id = v_id if v_id else None
v_id = v_id or None
if idonly:
return v_id
else:
Expand Down Expand Up @@ -1497,7 +1497,7 @@ def boundaries(self):
@mapinfo_must_be_set
def bbox(self, bbox=None):
"""Return bounding box of Isle"""
bbox = bbox if bbox else Bbox()
bbox = bbox or Bbox()
libvect.Vect_get_isle_box(self.c_mapinfo, self.id, bbox.c_bbox)
return bbox

Expand Down Expand Up @@ -1700,7 +1700,7 @@ def bbox(self, bbox=None):
:param bbox: a Bbox object to fill with info from bounding box of area
:type bbox: a Bbox object
"""
bbox = bbox if bbox else Bbox()
bbox = bbox or Bbox()
libvect.Vect_get_area_box(self.c_mapinfo, self.id, bbox.c_bbox)
return bbox

Expand Down Expand Up @@ -1798,7 +1798,7 @@ def cats(self, cats=None):
:param cats: a Cats object to fill with info with area categories
:type cats: a Cats object
"""
cats = cats if cats else Cats()
cats = cats or Cats()
libvect.Vect_get_area_cats(self.c_mapinfo, self.id, cats.c_cats)
return cats

Expand All @@ -1820,7 +1820,7 @@ def contains_point(self, point, bbox=None):
:param bbox: the bounding box where run the analysis
:type bbox: a Bbox object
"""
bbox = bbox if bbox else self.bbox()
bbox = bbox or self.bbox()
return bool(
libvect.Vect_point_in_area(
point.x, point.y, self.c_mapinfo, self.id, bbox.c_bbox
Expand Down Expand Up @@ -1897,8 +1897,8 @@ def read_next_line(
if c_cats is None:
free_cats = True

c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
c_cats = c_cats if c_cats else ctypes.pointer(libvect.line_cats())
c_points = c_points or ctypes.pointer(libvect.line_pnts())
c_cats = c_cats or ctypes.pointer(libvect.line_cats())
ftype, v_id, c_points, c_cats = c_read_next_line(c_mapinfo, c_points, c_cats)
return GV_TYPE[ftype]["obj"](
v_id=v_id,
Expand Down Expand Up @@ -1945,8 +1945,8 @@ def read_line(
if c_cats is None:
free_cats = True

c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
c_cats = c_cats if c_cats else ctypes.pointer(libvect.line_cats())
c_points = c_points or ctypes.pointer(libvect.line_pnts())
c_cats = c_cats or ctypes.pointer(libvect.line_cats())
feature_id, ftype, c_points, c_cats = c_read_line(
feature_id, c_mapinfo, c_points, c_cats
)
Expand Down
Loading

0 comments on commit a3543cd

Please sign in to comment.