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

Omit the corresponding key/value pairs when the value is None to use TOML serialization #421

Open
drunkwcodes opened this issue Aug 5, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@drunkwcodes
Copy link

I asked Toml maintainers to add null to TOML spec, and I got the reply which suggest me to omit the null key/value pairs.

toml-lang/toml#975

It is usual in python to use None, and TOML can not be used in these cases.
I really like TOML, can pyserde adjust serialization procedure to overcome this restriction?

@serde
@dataclass
class RingInfo:
    """Confrom mojo core-metadata"""

    name: str
    version: str
    metadata_version: str = "0.1"
    # Below are optional
    dynamic: list[str] | None = None
    platforms: list[str] | None = None
    supported_platforms: list[str] | None = None
    summary: str = ""
    description: str = ""
    description_content_type: str = "text/markdown"
    keywords: list[str] | None = None
    home_page: str = ""
    download_url: str = ""
    author: str = get_user_email_from_git()[0]
    author_email: str = get_user_email_from_git()[1]
    maintainer: str = get_user_email_from_git()[0]
    maintainer_email: str = get_user_email_from_git()[1]
    license: str = ""
    classifiers: list[str] | None = None
    requires_dist: list[str] | None = None
    requires_mojo: str = ""
    requires_external: list[str] | None = None
    project_urls: dict[str, str] | None = None
    provides_extra: list[str] | None = None
    provides_dist: list[str] | None = None
    obsoletes_dist: list[str] | None = None
    file_name: str = ""
@slonik-az
Copy link

What happens if None is part of array? Are you making array shorter and shifting all the values that followed the None?

I still cannot wrap my head around why TOML is fighting against having null tooth and nail.

@yukinarit
Copy link
Owner

Hi sorry for the delay. I was just back from vacation. What will happen if you pass an object with null property to toml?

@drunkwcodes
Copy link
Author

@yukinarit It will raise an error and stop serializing.

@yukinarit yukinarit added the enhancement New feature or request label Sep 7, 2023
@yukinarit yukinarit self-assigned this Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Considering 🤔
Development

No branches or pull requests

3 participants