lexyeevee

troublesome fox girl

hello i like to make video games and stuff and also have a good time on the computer. look @ my pinned for some of the video games and things. sometimes i am horny on @squishfox



ok so i'm in the market for a data file and i see python has a tomllib now. i've never actually used toml for anything but i thought i'd give it a whirl, why not.

first observation: you can't make, like, verbose lists. like [foo] is always a dict key, never a list entry. well that kind of sucks but ok. disregard i suck cocks, [[foo]] headers make lists, thank u @porglezomp

but then i see tomllib.loads takes a str, whereas tomllib.load takes a file specifically opened in binary mode. huh what

i check the stdlib source and

def load(fp: BinaryIO, /, *, parse_float: ParseFloat = float) -> dict[str, Any]:
    """Parse TOML from a binary file object."""
    b = fp.read()
    try:
        s = b.decode()
    except AttributeError:
        raise TypeError(
            "File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`"
        ) from None
    return loads(s, parse_float=parse_float)

????????????

who wrote this like this. WHy is this lik ethis


edit: omg the spec even LITERALLY SAYS

A TOML file must be a valid UTF-8 encoded Unicode document.

so why is the stdlib using the default encoding?? ?? ? ???? ? ?


wait it's not, bytes.decode() defaults to utf-8? that is news to me. ok so the whole idea is to enforce utf8 on a toml file. Well then nevermind this entire goddamn post


You must log in to comment.

in reply to @lexyeevee's post:

what OH so you can, ok that's much better

that seems ok. i think ini style is to just do [foo] more than once and obviously it's nice to, uh, know, when that's supposed to happen, and also not blow up in the case of a list of one

the pep even says it should use a binary file to ensure it's utf-8 encoded. maybe it's a mistake?

Using a binary file allows us to ensure UTF-8 is the encoding used (ensuring correct parsing on platforms with other default encodings, such as Windows), and avoid incorrectly parsing files containing single carriage returns as valid TOML due to universal newlines in text mode.