From cba083103c27df2924efc5a9c70073b0963d1d0d Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 6 Feb 2018 07:29:39 -0500 Subject: [PATCH] Use default argument of max() in capi bindings --- openmc/capi/cell.py | 5 +---- openmc/capi/filter.py | 5 +---- openmc/capi/material.py | 5 +---- openmc/capi/tally.py | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/openmc/capi/cell.py b/openmc/capi/cell.py index 3c14aae52..0ab3f2583 100644 --- a/openmc/capi/cell.py +++ b/openmc/capi/cell.py @@ -65,10 +65,7 @@ class Cell(_FortranObjectWithID): if new: # Determine ID to assign if uid is None: - try: - uid = max(mapping) + 1 - except ValueError: - uid = 1 + uid = max(mapping, default=0) + 1 else: if uid in mapping: raise AllocationError('A cell with ID={} has already ' diff --git a/openmc/capi/filter.py b/openmc/capi/filter.py index ac78c0a34..79c19a624 100644 --- a/openmc/capi/filter.py +++ b/openmc/capi/filter.py @@ -66,10 +66,7 @@ class Filter(_FortranObjectWithID): if new: # Determine ID to assign if uid is None: - try: - uid = max(mapping) + 1 - except ValueError: - uid = 1 + uid = max(mapping, default=0) + 1 else: if uid in mapping: raise AllocationError('A filter with ID={} has already ' diff --git a/openmc/capi/material.py b/openmc/capi/material.py index 8a55c2717..62d6df012 100644 --- a/openmc/capi/material.py +++ b/openmc/capi/material.py @@ -78,10 +78,7 @@ class Material(_FortranObjectWithID): if new: # Determine ID to assign if uid is None: - try: - uid = max(mapping) + 1 - except ValueError: - uid = 1 + uid = max(mapping, default=0) + 1 else: if uid in mapping: raise AllocationError('A material with ID={} has already ' diff --git a/openmc/capi/tally.py b/openmc/capi/tally.py index f50a19001..a78347177 100644 --- a/openmc/capi/tally.py +++ b/openmc/capi/tally.py @@ -155,10 +155,7 @@ class Tally(_FortranObjectWithID): if new: # Determine ID to assign if uid is None: - try: - uid = max(mapping) + 1 - except ValueError: - uid = 1 + uid = max(mapping, default=0) + 1 else: if uid in mapping: raise AllocationError('A tally with ID={} has already '