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

Replace TextIO with IO[…] in rtoml.load signature #58

Open
homeworkprod opened this issue Dec 16, 2022 · 0 comments
Open

Replace TextIO with IO[…] in rtoml.load signature #58

homeworkprod opened this issue Dec 16, 2022 · 0 comments

Comments

@homeworkprod
Copy link
Contributor

I've had typing issues with rtoml.load accepting TextIO twice by now. Can't fully recreate the first situation, but the second is loading a TOML config file in Flask.

Flask's flask.Config.from_file has a load parameter whose type is documented as

Callable[[Reader], Mapping] where Reader implements a read method

and implemented as Callable[[IO[Any]], Mapping].

Trying to use rtoml with it like so:

import rtoml
app.config.from_file(config_filename, load=rtoml.load)

makes mypy unhappy:

Argument "load" to "from_file" of "Config" has incompatible type "Callable[[Union[str, Path, TextIO]], Dict[str, Any]]"; expected "Callable[[IO[Any]], Mapping[Any, Any]]"

Since type TextIO is a subclass of IO[str] with a few additional methods that rtoml does not use I suggest to change the signature to use IO[str] (or maybe even IO[Any] plus encoding handling?) instead of TextIO.

For comparison,

What do you think?

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

No branches or pull requests

1 participant