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

Not a homogeneous array #324

Open
barkorkos opened this issue Oct 14, 2020 · 9 comments
Open

Not a homogeneous array #324

barkorkos opened this issue Oct 14, 2020 · 9 comments
Labels
syntax: arrays Related to arrays

Comments

@barkorkos
Copy link

array with multiple types not allows. for example

test = [ [10,5], 4]
or
test = ["aaa", 5]

@eksortso
Copy link

Here's some context to put this in perspective. Version 0.5.0 of the TOML specification forbids arrays with mixed types, that is true. But, that requirement was dropped beginning with v1.0.0-rc.1. Conformant TOML parsers will no longer need to reject arrays for mixing types.

That said, toml._spec_ is currently set to "0.5.0". So the error for multi-type arrays still needs to be raised.

@spapanik
Copy link

spapanik commented Nov 2, 2020

I don't think that it has to be raised. Quoting the toml-lang README:

All implementations are strongly encouraged to become compatible with TOML 1.0.0 release candidates and provide feedback, to ease the transition to 1.0.0, when it is released.

@eksortso
Copy link

eksortso commented Nov 2, 2020

Good catch. Then heterogeneous array support will be needed.

@ksunden
Copy link

ksunden commented Jan 20, 2021

Note that no exception is raised on write, only on read, resulting in data written by the library which cannot be read back.

@sethcall
Copy link

sethcall commented May 26, 2021

PR: #365

@pradyunsg pradyunsg added the syntax: arrays Related to arrays label Apr 20, 2022
@zoj613
Copy link

zoj613 commented Oct 26, 2022

Is there a reason why this hasn't been closed yet? also, how can I install the v1.0.0rc referenced in one of the above comments?

@ksunden
Copy link

ksunden commented Oct 26, 2022

@zoj613, consider using tomli instead, as it implements the latest toml spec.
Note that tomli is read only itself, but tomli-w is a separately installable package to do writing.

Tomli also is the toml library that was incorporated into the python standard library (as tomllib, read only) in Python 3.11 (just released this week)

@zoj613
Copy link

zoj613 commented Oct 26, 2022

@zoj613, consider using tomli instead, as it implements the latest toml spec. Note that tomli is read only itself, but tomli-w is a separately installable package to do writing.

Tomli also is the toml library that was incorporated into the python standard library (as tomllib, read only) in Python 3.11 (just released this week)

tomli does not support the _dict kwarg in its load function, which im making heavy use of to parse the data into a custom Dict object.

@eksortso
Copy link

Since the data types that tomli and tomllib apply are simple enough, you could feed the resulting configuration dict into a function that swaps out the dicts with your custom Dicts.

Assuming you have a custom Dict class CustomDict which accepts a regular dict for initialization, define the following:

def _into_CustomDict(origval):
    if isinstance(origval, dict):
        return CustomDict({k: _into_CustomDict(origval[k]) for k in origval})
    elif isinstance(origval, list):
        return [_into_CustomDict(tv) for tv in origval]
    else:
        return origval

Then run config = _into_CustomDict(config), and you have your custom dicts in place. And in Python 3.7+, the keys will be defined in the exact same order. This also assumes that your custom Dict objects don't do anything all that exotic, so make sure to test this. YMMV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax: arrays Related to arrays
Projects
None yet
Development

No branches or pull requests

7 participants