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

Add library stubs for use with mypy #2026

Closed
thofler opened this issue Oct 2, 2023 · 6 comments
Closed

Add library stubs for use with mypy #2026

thofler opened this issue Oct 2, 2023 · 6 comments

Comments

@thofler
Copy link

thofler commented Oct 2, 2023

Description of issue

It would be nice to be able to use mypy to check for issues in python applications using nidcpower (https://mypy.readthedocs.io/en/stable/).

Consider providing library stubs to enable this to work.

For applications using mypy to check other modules, need to disable checking nidcpower as described in the mypy docs:
[mypy-nidcpower.*]
ignore_missing_imports = True

@ni-jfitzger
Copy link
Collaborator

@thofler @marcoskirsch This seems like a duplicate of #1887 .
Based on the link in @thofler 's description, stub generation seems like something primarily created for users of libraries, not owners.

I think we'd prefer to add actual type hints. I don't think these stubs would be very useful.
From the documentation:

Stubgen generates draft stubs. The auto-generated stub files often require some manual updates, and most types will default to Any. The stubs will be much more useful if you add more precise type annotations, at least for the most commonly used functionality.

@ni-jfitzger
Copy link
Collaborator

Further explanation for @thofler. We code-generate our APIs based on metadata, with only a few hand-coded functions. It wouldn't make sense for us to have a bunch of manually-edited stubs. Better to just generate the annotations.

@marcoskirsch
Copy link
Member

marcoskirsch commented Oct 2, 2023

Seems like a duplicate of #1887

@ni-jfitzger
Copy link
Collaborator

We're in agreement, then. I'll close it.

@ni-jfitzger
Copy link
Collaborator

Duplicate of #1887

@ni-jfitzger ni-jfitzger marked this as a duplicate of #1887 Oct 2, 2023
@ni-jfitzger ni-jfitzger closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
@bkeryan
Copy link
Contributor

bkeryan commented Oct 2, 2023

Stub files are a way of adding type hints without changing your actual code. It doesn't matter to users whether you add type hints to your code or you add .pyi stub files.

You can even generate .pyi stub files if you want. That's what protoc does, if you opt in via the --mypy_out and --mypy_grpc_out options.

That said, I think the main reasons to use stub files (Python 2.x compatibility, package stubs separately from the code they are annotating) don't apply here, so it's better to add type hints to the actual code.

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

No branches or pull requests

4 participants