Regression - RepresenterError on dict subclass
See original GitHub issueDue to #126, I’m running pyyaml at master. When I try to run code that passes on released versions of pyyaml, it fails in master:
-> raise RepresenterError("cannot represent an object", data)
(Pdb) type(data)
<class 'pmxbot.dictlib.ConfigDict'>
(Pdb) isinstance(data, dict)
True
As the object is a subclass of dict, it would previously be treated as a dict for the purpose of serialization. Is this an intentional change?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
python - How to properly subclass dict and override __getitem ...
I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that...
Read more >What is more pythonic - subclassing dict or creating external ...
In general, in Python I favor using functions over subclassing internal classes. In the end, if you write your String -> dict method, ......
Read more >Using Counter - a Dictionary Subclass in Python - Template
Explore the Counter Dictionary subclass, learn how to determine the frequency of all characters in a string by downloading this free .ipynb template....
Read more >Understand __slots__ in Python - Towards Data Science
We use this dictionary to get and set attributes. ... Or, you don't put __slots__ in the subclass, it will by default have...
Read more >How To Work With Python Dictionary [With Code Examples]
This tutorial explains what is a Dictionary in Python and how to work ... It is a dict subclass that holds an integer...
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 tried using the dangerous dumper, but found that creates a YAML file that requires a dangerous loader. What I really want is to instruct YAML to serialize a dict subclass exactly as it would a dict.
I also ran into this issue trying to dump an instance of a dict subclass.
I found an ugly workaround on StackOverflow that you must run before calling
yaml.dump
:Limitations:
yaml.dump
but notyaml.safe_dump
.