Comments (9)
@Loreton note that the copy
method just do a normal dict.copy
and cast it to benedict
.
https://github.com/fabiocaccamo/python-benedict/blob/master/benedict/dicts/__init__.py#L56
Could you try to repeat the same test using the standard dict
please?
from python-benedict.
Sure...
--- s01_ptr:
{
"alias": "ptr_alias", <--- changed
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername" <--- changed
},
"host": "s01_host",
"location": {
"building": "ptr_building", <--- changed
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port"
}
--- s01_copy:
{
"alias": "ptr_alias", <--- changed
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername" <--- changed
},
"host": "s01_host",
"location": {
"building": "ptr_building", <--- changed
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port"
}
--- servers:
{
"SERVER": {
"S01": {
"alias": "ptr_alias", <--- changed
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername" <--- changed
},
"host": "s01_host",
"location": {
"building": "ptr_building", <--- changed
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port"
}
}
}
s01_ptr == s01_copy? True
s01_ptr == SERVER[S01]? True
s01_copy == SERVER[S01]? True
In this case s01_copy is the same as s01_ptr therefore it may not be considered.
Attached simple script to test the problem. You can enter 'benedict' or 'standard' to test one of them.
Regards
loreto
Benedict_test02a.zip
from python-benedict.
@Loreton thank you, I will test it as soon as possible.
from python-benedict.
@Loreton in the test02 you attached, you are not copying the dict
:
s01_ptr=servers['SERVER']['S01']
s01_copy=servers['SERVER']['S01'] # <- this should be: s01_copy=servers['SERVER']['S01'].copy()
from python-benedict.
@Loreton I added a test case for this issue: b9dfedf, it seems that the same error occurs with dict
.
I would ask you to check and test it, to run this specific test you should do:
- For each test method comment
@unittest.skip decorator
- Run
python -m unittest tests.github.test_issue_0025
from python-benedict.
@fabiocaccamo
You are right.
It was my mistake to include the .copy() example because it might take us out of the main purpose. My purpose is to figure out how to make a pointer using benedict (). If the following statement:
s01_ptr=benedict(servers['SERVER.S01'])
is the correct one to get a dict_pointer, then we have a different behavior from the standard:
s01_ptr=servers['SERVER']['S01']
If the statement was not correct, please help me to get the right sintax.
It almost seems that benedict() behaves like a shallow copy.
benedit dict result
--- s01_ptr:
{
"alias": "ptr_alias",
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername"
},
"host": "s01_host",
"location": {
"building": "ptr_building",
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port",
"z_ptr_add_item": 1224
}
--- servers:
{
"SERVER": {
"S01": {
"alias": "s01_alias",
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername"
},
"host": "s01_host",
"location": {
"building": "ptr_building",
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port"
}
}
}
s01_ptr == SERVER[S01]? False <--- benedict dict
Standard dict result:
--- s01_ptr:
{
"alias": "ptr_alias",
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername"
},
"host": "s01_host",
"location": {
"building": "ptr_building",
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port",
"z_ptr_add_item": 1224
}
--- servers:
{
"SERVER": {
"S01": {
"alias": "ptr_alias",
"credentials": {
"password": "s01_passw",
"username": "ptr_unsername"
},
"host": "s01_host",
"location": {
"building": "ptr_building",
"floar": "s01_floar",
"room": "s01_room"
},
"ssh_port": "s01_port",
"z_ptr_add_item": 1224
}
}
}
s01_ptr == SERVER[S01]? True <--- Standard dict
I hope now it's clearer and I'm sorry for the confusion I may have created.
Loreto
Attached new script without the copy() statement.
from python-benedict.
@Loreton could you please modify the test that I added to the tests suite?
from python-benedict.
@fabiocaccamo - Attached the modified tests suite file
github_issue_0025_test_case.zip
from python-benedict.
@Loreton the attached test is still not valid, check the difference with the updated test on master.
from python-benedict.
Related Issues (20)
- Missing dependency on pyyaml HOT 3
- keyattr dynamic or AttributeError HOT 5
- INI support for case sensitive keys HOT 6
- `from_ini()` returns a `str` instead of a `dict` HOT 21
- Support defining how input data is loaded (filepath, url or data-string) HOT 3
- Assigning benedict element to itself clears the element HOT 2
- Minimalize dependencies and define scope HOT 1
- Move some requirements to a new `parse` extra requirement.
- Exception when comparing with Protocol classes HOT 7
- Yaml serializer produces inconsistent results HOT 5
- Add `from_html` method. HOT 2
- iterating benedict_dictionary.items(), value is not benedict_type HOT 2
- Union with assignment operator produces inconsistent results compared to `dict`. HOT 2
- README Index links don't work on PyPI, only GitHub's markdown renderer HOT 2
- Bug: Passing `data_only=True` into `from_xls()` returns excel formulas instead of cell data values HOT 5
- RecursionError while initializing from existing dict HOT 3
- Optionally allow `keypath_separator` in input dict keys (`unflatten`). HOT 6
- Benedict with Realtime Sync accross Processes HOT 7
- utility method clean does not work for nested dicts HOT 3
- add funtion SuperFlatten feature, Flatten multi-level dictionary to 1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-benedict.