AI-multimodal / aimmdb

BSD 3-Clause "New" or "Revised" License
0 stars 10 forks source link

Quality of life: use @cache instead of global variable #22

Closed matthewcarbone closed 2 years ago

matthewcarbone commented 2 years ago

@kleinhenz I'm just perusing through the code and making issues as I go btw. Hope this is ok. Just trying to understand it better and help improve where I can 😊

https://github.com/AI-multimodal/aimmdb/blob/673b5ce88ef21ec259c5a262712e58ad9c31e2a6/aimmdb/utils.py#L40

Nitpick: I think you can do something like

from functools import cache

@cache 
def get_element_data():
    fname = importlib.resources.files("aimmdb") / "data" / "elements.json"
    with open(fname, "r") as f:
        data = json.load(f)
    return data

instead of using global. Less lines of code and safer.

kleinhenz commented 2 years ago

yeah that's probably cleaner. feel free to make a pr.