Updated to annotations instead of dir

This commit is contained in:
SimpleArt
2021-05-06 18:39:53 -04:00
parent 9a60416e1d
commit f140112980

View File

@ -1,5 +1,4 @@
import sqlite3 import sqlite3
import os
from tabulate import tabulate from tabulate import tabulate
@ -59,9 +58,8 @@ class SQL_Database:
db_config_dict = ( db_config_dict = (
(attr_name, getattr(ga, attr_name)) (attr_name, getattr(ga, attr_name))
for attr_name for attr_name
in dir(ga) in ga.__annotations__
if attr_name[0] != '_' if attr_name != "population"
if attr_name != 'population'
) )
# Types supported in the database # Types supported in the database
@ -70,17 +68,14 @@ class SQL_Database:
# Loop through all attributes # Loop through all attributes
for name, value in db_config_dict: for name, value in db_config_dict:
# Inserting a function, do special stuff # not a function
if callable(value): if not callable(value):
value = ""
# Not a function
else:
# Convert to the right type # 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 # Insert into database
self.conn.execute(f""" self.conn.execute(f"""
INSERT INTO config(config_id, attribute_name, attribute_value) INSERT INTO config(config_id, attribute_name, attribute_value)