1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-06 01:12:40 +02:00

tools: fix deprecated syntax.

This fixes a similar deprecation warning on various pieces of code:

> DeprecationWarning: Testing an element's truth value will always return True in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.
>   samples = log.find ("samples") or empty_element
This commit is contained in:
Jehan
2024-09-26 19:49:47 +02:00
parent 05c86dad8a
commit 1726a6f89f
5 changed files with 27 additions and 23 deletions

View File

@@ -32,7 +32,7 @@ log = ElementTree.fromstring (sys.stdin.buffer.read ())
address_map = log.find ("address-map")
if address_map:
if address_map is not None:
addresses = []
# Create base addresses dictionary

View File

@@ -35,8 +35,8 @@ log = ElementTree.fromstring (sys.stdin.buffer.read ())
# Construct state histogram
address_states = {}
for sample in (log.find ("samples") or empty_element).iterfind ("sample"):
threads = (sample.find ("backtrace") or empty_element).iterfind ("thread")
for sample in (log.find ("samples") if log.find ("samples") is not None else empty_element).iterfind ("sample"):
threads = (sample.find ("backtrace") if sample.find ("backtrace") is not None else empty_element).iterfind ("thread")
for thread in threads:
running = int (thread.get ("running"))
@@ -73,8 +73,8 @@ for address, states in list (address_states.items ()):
del address_states[address]
# Replace thread states
for sample in (log.find ("samples") or empty_element).iterfind ("sample"):
threads = (sample.find ("backtrace") or empty_element).iterfind ("thread")
for sample in (log.find ("samples") if log.find ("samples") is not None else empty_element).iterfind ("sample"):
threads = (sample.find ("backtrace") if sample.find ("backtrace") is not None else empty_element).iterfind ("thread")
for thread in threads:
frame = thread.find ("frame")

View File

@@ -49,17 +49,19 @@ def expand_simple (element, last_values):
last_vars = {}
last_backtrace = {}
for sample in (log.find ("samples") or empty_element).iterfind ("sample"):
for sample in (log.find ("samples") if log.find ("samples") is not None else empty_element).iterfind ("sample"):
# Expand variables
vars = sample.find ("vars") or \
ElementTree.SubElement (sample, "vars")
vars = sample.find ("vars")
if vars is None:
vars = ElementTree.SubElement (sample, "vars")
expand_simple (vars, last_vars)
# Expand backtrace
if has_backtrace:
backtrace = sample.find ("backtrace") or \
ElementTree.SubElement (sample, "backtrace")
backtrace = sample.find ("backtrace")
if backtrace is None:
backtrace = ElementTree.SubElement (sample, "backtrace")
for thread in backtrace:
id = thread.get ("id")
@@ -100,7 +102,7 @@ for sample in (log.find ("samples") or empty_element).iterfind ("sample"):
# Expand address map
last_address = {}
for address in (log.find ("address-map") or empty_element).iterfind ("address"):
for address in (log.find ("address-map") if log.find ("address-map") is not None else empty_element).iterfind ("address"):
expand_simple (address, last_address)
# Write performance log to STDOUT

View File

@@ -30,25 +30,27 @@ empty_element = ElementTree.Element ("")
# Read performance log from STDIN
log = ElementTree.fromstring (sys.stdin.buffer.read ())
samples = log.find ("samples") or empty_element
samples = log.find ("samples")
if samples is None:
samples = empty_element
address_map = log.find ("address-map")
if not address_map:
address_map = ElementTree.Element ("address-map")
if address_map is None:
address_map = ElementTree.Element ("address-map")
# Coalesce partial address maps
for partial_address_map in samples.iterfind ("address-map"):
for element in partial_address_map:
address_map.append (element)
for element in partial_address_map:
address_map.append (element)
# Remove partial address maps
for partial_address_map in samples.iterfind ("address-map"):
samples.remove (partial_address_map)
samples.remove (partial_address_map)
# Add global address map
if not log.find ("address-map") and len (address_map) > 0:
log.append (address_map)
if log.find ("address-map") is None and len (address_map) > 0:
log.append (address_map)
# Write performance log to STDOUT
sys.stdout.buffer.write (ElementTree.tostring (log))

View File

@@ -252,7 +252,7 @@ AddressInfo = namedtuple ("AddressInfo", ("id",
address_map = {}
if log.find ("address-map"):
if log.find ("address-map") is not None:
for address in log.find ("address-map").iterfind ("address"):
value = int (address.get ("value"), 0)
@@ -308,7 +308,7 @@ for element in log.find ("samples"):
raw = var.text.strip () if var.text else None
)
if element.find ("backtrace"):
if element.find ("backtrace") is not None:
for thread in element.find ("backtrace").iterfind ("thread"):
id = thread.get ("id")
name = thread.get ("name")
@@ -1671,12 +1671,12 @@ class InformationViewer (Gtk.ScrolledWindow):
params = log.find ("params")
if params:
if params is not None:
add_element (params)
info = log.find ("info")
if info:
if info is not None:
for element in info:
add_element (element)