From f140112980b6544c1d24ff5b2b8ceb4e8ece76e9 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Thu, 6 May 2021 18:39:53 -0400 Subject: [PATCH] Updated to annotations instead of dir --- EasyGA/database/sql_database.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/EasyGA/database/sql_database.py b/EasyGA/database/sql_database.py index c9b5e0a..cc0344d 100644 --- a/EasyGA/database/sql_database.py +++ b/EasyGA/database/sql_database.py @@ -1,5 +1,4 @@ import sqlite3 -import os from tabulate import tabulate @@ -59,9 +58,8 @@ class SQL_Database: db_config_dict = ( (attr_name, getattr(ga, attr_name)) for attr_name - in dir(ga) - if attr_name[0] != '_' - if attr_name != 'population' + in ga.__annotations__ + if attr_name != "population" ) # Types supported in the database @@ -70,21 +68,18 @@ class SQL_Database: # Loop through all attributes for name, value in db_config_dict: - # Inserting a function, do special stuff - if callable(value): - value = "" + # not a function + if not callable(value): - # Not a function - else: # Convert to the right type - if type(value) not in sql_type_list: + value = str(value) - value = str(value) + if "'" not in value and '"' not in value: - # Insert into database - self.conn.execute(f""" - INSERT INTO config(config_id,attribute_name, attribute_value) - VALUES ('{self.config_id}', '{name}','{value}');""") + # Insert into database + self.conn.execute(f""" + INSERT INTO config(config_id, attribute_name, attribute_value) + VALUES ('{self.config_id}', '{name}','{value}');""") self.config_id = self.get_current_config()