Timeline for How to handle configuration from a config file and global variables transparently in python?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 27, 2021 at 9:41 | comment | added | Andreas Schuldei | I looked at Pydantic, and I think you are right. It is even better than TypedDict. Would you please update your code to use it? Then I would like to accept your answer as the solution to this question. (regardless, I will use your approach with Pydantic in my project, but you would get your karma. :-) @martin-thoma | |
Dec 26, 2021 at 17:54 | comment | added | Martin Thoma |
It is completely correct that JSON cannot serialize native Python objects in many cases. Best example is datetime and uuid . However, there you have to ask yourself if you need that. IMHO, a configuration file format should not need the power to serialize native Python code. Having less power is good in this case. Formats like pickle are more powerful, but then you need to worry about security (arbitrary code execution when pickle files are loaded)
|
|
Dec 26, 2021 at 15:25 | comment | added | Andreas Schuldei | I refer to Xeнεi Ξэnвϵς. above, he wrote: "Also JSON is not Python, Python has many objects that aren't JSON serializable (set, frozenset, byte, bytearry, complex...), and some objects when deserialized will change their datatypes, so if you want to keep the identity of the objects you'd better use native serializer". I am not an expert - I try to ask one expert about an other expert's opinion. :-) feel free to comment on his answer, I would like to read your exchange. (and vice versa) | |
Dec 26, 2021 at 11:55 | comment | added | Martin Thoma | @AndreasSchuldei I've added pydantic as a comment because it is a third-party module. I typically prefer not to rely on 3rd party modules in answers if possible. However, I would use Pydantic for this case if I wrote code for this | |
Dec 26, 2021 at 11:52 | comment | added | Martin Thoma | @AndreasSchuldei I cannot see any comment by "Heisenberg". But JSON is a general data exchange format. It's just as good/bad for Python as for other languages. One major flaw I see in JSON as a config file format is that you cannot add comments. That is the reason why I typically use YAML, but some people hate YAML. Some people like TOML. Others prefer pure Python as config files. | |
Dec 26, 2021 at 9:04 | comment | added | Andreas Schuldei | you suggest first TypedDict (to help with the hinting in the IDE?) and then write that you would use Pydantic instead of TypedDict. Can you please reconcile that? Like this Pydantic feels like an afterthought and your answer comes across like half-cooked. | |
Dec 25, 2021 at 14:43 | comment | added | Andreas Schuldei | no, i didnt know about TypedDict. Thanks for introducing me to it! What do you say about what user "Heisenberg" writes above about json being suboptimal for python? I do fancy your package and also your solution. | |
Dec 25, 2021 at 11:36 | history | answered | Martin Thoma | CC BY-SA 4.0 |