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

Incomplete type hints for zmq.Socket.recv_json #2066

Open
joshMaybell opened this issue Feb 5, 2025 · 3 comments
Open

Incomplete type hints for zmq.Socket.recv_json #2066

joshMaybell opened this issue Feb 5, 2025 · 3 comments

Comments

@joshMaybell
Copy link

The recv_json method of the zmq.Serial class has its return type listed as: list | str | int | float | dict. list and dict require generic arguments for this return type to be complete. As is, users of this class cannot fully benefit from static analysis.

@minrk
Copy link
Member

minrk commented Feb 5, 2025

Yeah, it could be more detailed to specify everything that JSON might be, but what's there now should at least be fully correct, if slightly more expansive than necessary. What problem do you see?

@joshMaybell
Copy link
Author

joshMaybell commented Feb 5, 2025

When using this function in a project that adheres to strict type checking (at least for pyright, I'm not sure about mypy), code that uses this function carries around an Unknown type. Thus, any code that's using it gets hit with:

Type of "req" is partially unknown
  Type of "req" is "list[Unknown] | str | int | float | dict[Unknown, Unknown]"

For a json type, something like the following would make static analysis on zmq code more robust.

JsonType: TypeAlias = None | int | str | bool | list["JsonType"] | dict[str, "JsonType"]
...
def recv_json(self, flags: int = 0, **kwargs: Any) -> JsonType):
    ...

Of course, this can be done in custom stub files for the library on a per-project basis where needed, but its nice to not need to maintain stubs when possible.

@minrk
Copy link
Member

minrk commented Feb 5, 2025

OK, I don't use pyright, it does seem to make a mess of things. Feel free to make a PR if you like.

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

2 participants