[bug] HOCONConverter relativedelta as value
See original GitHub issueBefore 0.3.51:
from pyhocon import ConfigFactory, HOCONConverter
conf = ConfigFactory.parse_string('key: 10s')
# ConfigTree([('key', '10s')])
HOCONConverter.to_json(conf)
# '{\n "key": "10s"\n}'
HOCONConverter.to_yaml(conf)
# 'key: 10s'
HOCONConverter.to_hocon(conf)
# 'key = "10s"'
HOCONConverter.to_properties(conf)
# 'key = 10s'
After:
from pyhocon import ConfigFactory, HOCONConverter
conf = ConfigFactory.parse_string('key: 10s')
# ConfigTree([('key', relativedelta(seconds=+10))])
HOCONConverter.to_json(conf)
# '{\n "key": relativedelta(seconds=+10)\n}'
HOCONConverter.to_yaml(conf)
# 'key: relativedelta(seconds=+10)'
HOCONConverter.to_hocon(conf)
# 'key = relativedelta(seconds=+10)'
HOCONConverter.to_properties(conf)
# 'key = relativedelta(seconds=+10)'
It’s not possible to use result of such export in other languages/applications without custom config parsers. IMHO the best option here is to add some option to parser to enable/disable such cast of config values.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Issues · chimpler/pyhocon - GitHub
Overriding a value multiple times fails to resolve. #274 opened on Oct 25, ... [bug] HOCONConverter relativedelta as value. #246 opened on Oct...
Read more >python dateutil relativedelta value out of range error
I am fond of dateutil module so i am just curious why it didn't work. Example date passed: 2014-02-26. Any ideas? python ·...
Read more >relativedelta — dateutil 2.8.2 documentation - Read the Docs
The relativedelta type is designed to be applied to an existing datetime and ... value in the original datetime with the value(s) in...
Read more >pyhocon Changelog - pyup.io
Support serializing timedelta and relativedelta to string (hocon, json etc.) ... fixed bug when we insert None values that shouldn't raise an exception...
Read more >Python relativedelta to get duration of difference ... - Plus2net
day and days from dateutil.relativedelta import relativedelta from datetime import date dt=date.today() # today is 2019-09-23 # Adding one day to today ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the main problem here is that, if I’m not mistaken, pyhocon does not keep the original document, but converts everything to what it believes to be the native data type, right when parsing. If conversion between data types is lossless, that’s no problem (e.g. ‘1’ -> 1 -> ‘1’), but in case of periods of time (or what looks like it), converting back does not work anymore.
I think
get_string()
would need to operate on a separate data structure that provides the original value strings. With the current implementation, not only does one not have access to the original string value, but also there’s no way to have values that look like periods of time.E.g. I might want to store a hash in a config that happens to contain only numbers and a letter at the end:
get_string('hash')
returns “relativedelta(days=+5.14403e+06, hours=+21)”. I don’t see how one could deal with that… so sadly I think pyhocon must be considered broken in that respect.(The only option is to explicitly declare the value to be a string by enclosing it in “”, but that may not be a valid thing to do in some use cases.)
Moved to https://github.com/omry/omegaconf, it does support many features present in HOCON but it does not mess up with parsing date types