Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Incomplete implementation of dictset.__getattr__ #144

Open
vlcinsky opened this issue Jul 22, 2016 · 5 comments
Open

Incomplete implementation of dictset.__getattr__ #144

vlcinsky opened this issue Jul 22, 2016 · 5 comments

Comments

@vlcinsky
Copy link

vlcinsky commented Jul 22, 2016

https://github.com/ramses-tech/nefertari/blob/master/nefertari/utils/dictset.py#L29 fails when request for non-existent attribute is done.

In some situation the problem may be hidden by using simplejson with installed speedups.

PR #143 resolves the problem.

@vlcinsky vlcinsky changed the title Incomplete implementation of dictset.__getattrib__ Incomplete implementation of dictset.__getattr__ Jul 24, 2016
@jstoiko
Copy link
Member

jstoiko commented Jul 25, 2016

hey @vlcinsky thanks for the PR!

can you provide some steps to reproduce this?

@vlcinsky
Copy link
Author

vlcinsky commented Jul 25, 2016

To reproduce the problem, see ramses-tech/ramses-example#59

@jstoiko
Copy link
Member

jstoiko commented Jul 25, 2016

Missed that. Did you install following these steps inside a virtualenv?

@vlcinsky
Copy link
Author

Yes, to manage virtualenvs I use tox from which I request installation of packages listed in requirements.txt. Tested for Python 2.7.12 and 3.5.2 on Ubuntu 16.04.

@vlcinsky
Copy link
Author

vlcinsky commented Jul 25, 2016

Simple test is:

>>> from nefertari.utils.dictset import dictset
>>> dset = dictset({"a": 11, "b": 22})
>>> dset["a"]
11
>>> dset["b"]
22
>>> dset.a
11
>>> dset.b
22
>>> dset.c
KeyError                                  Traceback (most recent call last)
<ipython-input-xy> in <module>()
----> 1 getattr(dset, "c", None)

.tox/py27/local/lib/python2.7/site-packages/nefertari/utils/dictset.pyc in __getattr__(self, key)
     28 
     29     def __getattr__(self, key):
---> 30         return self[key]
     31 
     32     def __setattr__(self, key, val):
KeyError: 'c'
>>> getattr(dset, "a", None)
11
>>> getattr(dset, "b", None)
22
>>> getattr(dset, "c", None)
KeyError                                  Traceback (most recent call last)
<ipython-input-xy> in <module>()
----> 1 getattr(dset, "c", None)

.tox/py27/local/lib/python2.7/site-packages/nefertari/utils/dictset.pyc in __getattr__(self, key)
     28 
     29     def __getattr__(self, key):
---> 30         return self[key]
     31 
     32     def __setattr__(self, key, val):
KeyError: 'c'

Note the last error: asking for value of non-existent attribute using getattr shall not fail with KeyError, but shall provide the default value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants