Skip to content

Improve toml typings #7146

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

Merged
merged 17 commits into from
Feb 10, 2022
Merged

Improve toml typings #7146

merged 17 commits into from
Feb 10, 2022

Conversation

faresbakhit
Copy link
Contributor

Add toml's full API. Fixes #6484.

Fares Ahmed added 2 commits February 6, 2022 20:45
@faresbakhit
Copy link
Contributor Author

I'm not sure if it is correct to use TomlDecoder(Generic[_T]). Should I have just used MutableMapping[str, Any] instead?

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! toml is now deprecated and many projects are switching to tomli instead, but we still accept improvements to the toml stubs.

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! It has turned out to be trickier than I expected :)

@faresbakhit
Copy link
Contributor Author

Finally, Got the tests to pass 😄!

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple final things, then this will be ready :)

@faresbakhit
Copy link
Contributor Author

In __init__.pyi, should this be preferred over the current one?

from . import decoder as decoder, encoder as encoder
from .decoder import (
    TomlDecodeError as TomlDecodeError,
    TomlDecoder as TomlDecoder,
    TomlPreserveCommentDecoder as TomlPreserveCommentDecoder,
    load as load,
    loads as loads,
)
from .encoder import (
    TomlArraySeparatorEncoder as TomlArraySeparatorEncoder,
    TomlEncoder as TomlEncoder,
    TomlNumpyEncoder as TomlNumpyEncoder,
    TomlPathlibEncoder as TomlPathlibEncoder,
    TomlPreserveCommentEncoder as TomlPreserveCommentEncoder,
    TomlPreserveInlineDictEncoder as TomlPreserveInlineDictEncoder,
    dump as dump,
    dumps as dumps,
)

VSCode's ms-python.python extension currently highlights the functions and classes as variables which looks a bit bad but in reality they are really variables just as defined in toml's source code. What do you think?
image

@Akuli
Copy link
Collaborator

Akuli commented Feb 10, 2022

Both import styles are acceptable. If one produces better syntax highlighting than the other, use whichever highlights better :)

Provide better highlighting in code editors to recognize exported
functions and classes as them instead of variables
@faresbakhit
Copy link
Contributor Author

Okay then, I think this is it! 😄

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Akuli Akuli merged commit 7efda0f into python:master Feb 10, 2022
@JelleZijlstra
Copy link
Member

Both import styles are acceptable. If one produces better syntax highlighting than the other, use whichever highlights better :)

This is about from ... import X as X vs. X = X, right? I think it makes sense to standardize on the first style in general. We could probably enforce it in flake8-pyi.

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

Successfully merging this pull request may close these issues.

TOML stubs incomplete
3 participants