alexferl / vyper

Python configuration with (more) fangs
MIT License
144 stars 21 forks source link

Environment variables overriding defaults within a subclass #31

Closed Dandb79 closed 4 years ago

Dandb79 commented 4 years ago

Consider the following example:

from vyper import Vyper  
from os import environ as env  
env['CLASS.KEY2'] = 'newval2'  
v = Vyper(key_delimiter='.')  
v.set_default('class.key1', 'val1')  
v.set_default('class.key2', 'val2')  
v.set_default('class.key3', 'val3')  
v.bind_env('class.key1')  
v.bind_env('class.key2')  
v.bind_env('class.key3')  
print(v.get('class.key1'))  

The expected behaviour would be to output val1 but instead the following stack trace occurs:

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    print(v.get('class.key1'))
  File "/home/dandb/anaconda3/lib/python3.7/site-packages/vyper/vyper.py", line 186, in get
    val = self._find(lowercase_key)
  File "/home/dandb/anaconda3/lib/python3.7/site-packages/vyper/vyper.py", line 409, in _find
    source = self._find(path[0])
  File "/home/dandb/anaconda3/lib/python3.7/site-packages/vyper/vyper.py", line 382, in _find
    self._set_insensitive(item["final_key"], val, temp)
  File "/home/dandb/anaconda3/lib/python3.7/site-packages/vyper/vyper.py", line 324, in _set_insensitive
    real_key = self._find_real_key(key, source)
  File "/home/dandb/anaconda3/lib/python3.7/site-packages/vyper/vyper.py", line 316, in _find_real_key
    (real for real in source.keys() if real.lower() == key.lower()), None
AttributeError: 'NoneType' object has no attribute 'keys'
Dandb79 commented 4 years ago

Hi there,

Any updates regarding this issue or my solution from your end?

alexferl commented 4 years ago

Fixed in v0.6.2, thanks for the PR!