rtoml
rtoml copied to clipboard
Replace `TextIO` with `IO[…]` in `rtoml.load` signature
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]whereReaderimplements areadmethod
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,
- tomli expects
IO[bytes], and - tomlkit extects
IO.
What do you think?