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

TOML with inline tables is not pickleable #362

Open
moqmar opened this issue May 17, 2021 · 3 comments
Open

TOML with inline tables is not pickleable #362

moqmar opened this issue May 17, 2021 · 3 comments
Labels
component: decoder Related to parsing in `toml.load` type: bug A confirmed bug or unintended behavior

Comments

@moqmar
Copy link

moqmar commented May 17, 2021

Is there a reason why get_empty_inline_table uses a local class? It prevents the result from being pickled:

>>> pickle.dumps(toml.loads("test = { fail = true }"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Can't pickle local object 'TomlDecoder.get_empty_inline_table.<locals>.DynamicInlineTableDict'
@moqmar
Copy link
Author

moqmar commented May 17, 2021

Workaround:

>>> class PickleableTomlDecoder(toml.TomlDecoder):
...     def get_empty_inline_table(self):
...         return self.get_empty_table()
... pickle.dumps(toml.loads("test = { fail = true }", decoder=PickleableTomlDecoder()))
b'\x80\x04\x95\x16\x00\x00\x00\x00\x00\x00\x00}\x94\x8c\x04test\x94}\x94\x8c\x04fail\x94\x88ss.'

@amor71
Copy link

amor71 commented Jul 20, 2021

I noticed this too. When using multiprocessing, this is quite disruptive. @moqmar, I found a workaround in the TOML file (at least in my case). It seems like the issue occurs when assigning a dictionary (.e.g. x={a=1, b=2}). However, if the dictionary is broken into

[my.stuff.x]
a = 1
b = 2

It becomes pick-able. I hope this helps.

@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior component: decoder Related to parsing in `toml.load` labels Apr 20, 2022
@bulletRush
Copy link

you can also use json load to avoid this bug:

 json.loads(json.dumps(toml.load("xxxx.toml")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: decoder Related to parsing in `toml.load` type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants