Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttrDict returns empty AttrDict when key does not exist #14

Closed
AndrewEichmann-NOAA opened this issue Feb 15, 2024 · 1 comment · Fixed by #16
Closed

AttrDict returns empty AttrDict when key does not exist #14

AndrewEichmann-NOAA opened this issue Feb 15, 2024 · 1 comment · Fixed by #16
Assignees
Labels
bug Something isn't working

Comments

@AndrewEichmann-NOAA
Copy link

Expected behavior

When a non-existent key is used with an AttrDict, an exception should be thrown, assuming behavior is supposed to resemble a standard Python dictionary

Current behavior

When a key is not found, an empty AttrDict is returned

Machines affected

Hera

To Reproduce

#!/usr/bin/env python

from wxflow import AttrDict

local_dict = AttrDict(
    { "dasher": 'winken',
      "dancer": 'blinken',
      "comet":  'nod' }
     )


print(local_dict["dasher"])
print(type(local_dict["dasher"]))
print(local_dict["cupid"])
print(type(local_dict["cupid"]))
(gdasapp) -bash-4.2$ python attrdict.py 
winken
<class 'str'>
{}
<class 'wxflow.attrdict.AttrDict'>
(gdasapp) -bash-4.2$

Context

Trying to use paths in config structures with the type AttrDict and attempting to access non-existent entries as paths to be used as parameters to FileHandler results in confusing complaints from within FileHandler, which is expecting strings or path-like objects, not an empty AttrDict

Possible Implementation

Make it throw an exception like KeyError in the manner of dicts

@AndrewEichmann-NOAA AndrewEichmann-NOAA added the bug Something isn't working label Feb 15, 2024
@aerorahul
Copy link
Contributor

@AndrewEichmann-NOAA
Thank you for reporting the bug.
The branch should resolve the bug where a missing key is throws a KeyError instead of an empty dict in a manner consistent with dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants