From 7eb5e3d33bce0c5917bccb775ee052494b200db8 Mon Sep 17 00:00:00 2001
From: Nick Conway <a.grinner@gmail.com>
Date: Thu, 15 Feb 2024 11:17:09 -0500
Subject: [PATCH] Fix `_ThermoAnalysis._set_globals_and_seq_args` for improper
 checks on `misprime_lib` and `mishyb_lib` leading to incorrect initialization
 of `mp_lib` and `mh_lib`

---
 CHANGES                    |  5 +++++
 primer3/__init__.py        |  4 ++--
 primer3/thermoanalysis.pyx | 35 +++++++++++++++++++++--------------
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/CHANGES b/CHANGES
index 85a059e..4eba3f0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,10 @@
 # Changelog
 
+## Version 2.0.3 (February 15, 2024)
+
+- Fix `_ThermoAnalysis._set_globals_and_seq_args` for improper checks on `misprime_lib` and
+`mishyb_lib` leading to incorrect initialization of `mp_lib` and `mh_lib`. See issue #133
+
 ## Version 2.0.2 (February 9, 2024)
 
 - Support for python 3.12 (build, test, docs)
diff --git a/primer3/__init__.py b/primer3/__init__.py
index f2b1456..8bc27b4 100644
--- a/primer3/__init__.py
+++ b/primer3/__init__.py
@@ -26,10 +26,10 @@
 from typing import List
 
 # Per PEP-440 https://peps.python.org/pep-0440/#public-version-identifiers
-__version__ = '2.0.2'
+__version__ = '2.0.3'
 __author__ = 'Ben Pruitt, Nick Conway'
 __copyright__ = (
-    'Copyright 2014-2023, Ben Pruitt & Nick Conway; 2014-2018 Wyss Institute'
+    'Copyright 2014-2024, Ben Pruitt & Nick Conway; 2014-2018 Wyss Institute'
 )
 __license__ = 'GPLv2'
 DESCRIPTION = 'Python bindings for Primer3'
diff --git a/primer3/thermoanalysis.pyx b/primer3/thermoanalysis.pyx
index e773761..8d16ceb 100644
--- a/primer3/thermoanalysis.pyx
+++ b/primer3/thermoanalysis.pyx
@@ -1213,22 +1213,29 @@ cdef class _ThermoAnalysis:
         err_msg = ''
         try:
             global_settings_data = <p3_global_settings*> self.global_settings_data
-            if misprime_lib != None:
-                mp_lib = pdh_create_seq_lib(misprime_lib)
-                if mp_lib == NULL:
-                    err_msg = f'Issue creating misprime_lib {misprime_lib}'
-                    raise ValueError(
-                        f'Issue creating misprime_lib {misprime_lib}'
-                    )
 
-                global_settings_data[0].p_args.repeat_lib = mp_lib
+            if misprime_lib is None:
+                misprime_lib = {}
+
+            mp_lib = pdh_create_seq_lib(misprime_lib)
+            if mp_lib == NULL:
+                err_msg = f'Issue creating misprime_lib {misprime_lib}'
+                raise ValueError(
+                    f'Issue creating misprime_lib {misprime_lib}'
+                )
+
+            global_settings_data[0].p_args.repeat_lib = mp_lib
+
+            if mishyb_lib is None:
+                mishyb_lib = {}
+
+            mh_lib = pdh_create_seq_lib(mishyb_lib)
+            if mh_lib == NULL:
+                err_msg = f'Issue creating mishyb_lib: {mishyb_lib}'
+                raise ValueError(err_msg)
+
+            global_settings_data[0].o_args.repeat_lib = mh_lib
 
-            if mishyb_lib != None:
-                mh_lib = pdh_create_seq_lib(mishyb_lib)
-                if mh_lib == NULL:
-                    err_msg = f'Issue creating mishyb_lib: {mishyb_lib}'
-                    raise ValueError(err_msg)
-                global_settings_data[0].o_args.repeat_lib = mh_lib
         except (OSError, TypeError) as exc:
             p3_destroy_global_settings(
                 <p3_global_settings*> self.global_settings_data