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

[Feature Request]: Add library stubs or py.typed marker #27906

Open
1 of 15 tasks
davidcavazos opened this issue Aug 8, 2023 · 3 comments · Fixed by #27942
Open
1 of 15 tasks

[Feature Request]: Add library stubs or py.typed marker #27906

davidcavazos opened this issue Aug 8, 2023 · 3 comments · Fixed by #27942
Assignees
Labels
done & done Issue has been reviewed after it was closed for verification, followups, etc. new feature P2 python

Comments

@davidcavazos
Copy link
Contributor

davidcavazos commented Aug 8, 2023

What would you like to happen?

Support running mypy on my own Beam pipeline code by adding type stubs.

Simply importing apache_beam fails with mypy.

#-- main.py
import apache_beam as beam

Install and run mypy.

pip install mypy apache-beam

mypy main.py

Gives the following output:

main.py:1: error: Skipping analyzing "apache_beam": module is installed, but missing library stubs or py.typed marker  [import]
main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

They can be automatically generated with stubgen, it would be nice to make that part of the release process on each new version. Since Beam already has type hints, I don't think there is too much tweaking needed.

I did try to generate them, but it failed trying to parse some complex type hint.

Issue Priority

Priority: 2 (default / most feature requests should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
@davidcavazos
Copy link
Contributor Author

davidcavazos commented Aug 8, 2023

I'm not too familiar with this, but it looks like other libraries with inline type annotations like Beam simply place an "empty" py.typed marker file.

@davidcavazos
Copy link
Contributor Author

I just tested adding a file like that and it works.

@github-actions github-actions bot added this to the 2.51.0 Release milestone Sep 19, 2023
@jrmccluskey jrmccluskey added the done & done Issue has been reviewed after it was closed for verification, followups, etc. label Oct 17, 2023
@gariepyalex
Copy link

gariepyalex commented Nov 27, 2023

Can we re-open this issue? I installed version 2.52 I still have the error

main.py:1: error: Skipping analyzing "apache_beam": module is installed, but missing library stubs or py.typed marker  [import]
main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

I looked into the installed package and py.typed is not distributed.

It should be added as a new file inpackage_data:
https://github.com/apache/beam/blob/master/sdks/python/setup.py#L254

I could find for info there: https://peps.python.org/pep-0561/#packaging-type-information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done & done Issue has been reviewed after it was closed for verification, followups, etc. new feature P2 python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants