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

load, dump: type fp as IO[str] #22

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

liamstask
Copy link
Contributor

@liamstask liamstask commented Apr 13, 2024

Similar to python/typeshed#283, typing complains that the IO[Any] returned from open() is not compatible with TextIO - take the advice there and accept IO[str] instead.

Copy link
Owner

@n-takumasa n-takumasa left a comment

Choose a reason for hiding this comment

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

Thank you for the PR.
I think SupportsXxx[str] would be better.

@@ -40,7 +40,7 @@


def load(
fp: TextIO,
fp: IO[str],
Copy link
Owner

Choose a reason for hiding this comment

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

SupportsRead[str]

https://github.com/python/typeshed/blob/7c8e82fe483a40ec4cb0a2505cfdb0f3e7cc81d9/stdlib/json/__init__.pyi#L51

json.detect_encoding seems to be undocumented, so I would like to postpone support for bytes.

@@ -144,7 +144,7 @@ def dumps(

def dump(
obj: Any,
fp: TextIO,
fp: IO[str],
Copy link
Owner

Choose a reason for hiding this comment

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

@liamstask
Copy link
Contributor Author

hm, those annotations appear to be typeshed internal: https://github.com/python/typeshed/blob/7c8e82fe483a40ec4cb0a2505cfdb0f3e7cc81d9/stdlib/json/__init__.pyi#L1

I'm not sure of the preferred way to translate between those and the public typing annotations

@n-takumasa n-takumasa merged commit 715b450 into n-takumasa:main Apr 16, 2024
10 checks passed
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.

2 participants