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

Adds a basic stub file generator #369

Merged
merged 25 commits into from Jan 17, 2024
Merged

Adds a basic stub file generator #369

merged 25 commits into from Jan 17, 2024

Conversation

davidselassie
Copy link
Contributor

  • Adds stubgen
  • Moves PyO3 inner module to _bytewax
  • stubgen no longer emits trailing whitespace in docstrings
  • Fixes all Python docstrings in Rust code to have proper formatting
  • Topo sorts stubgen output so subclasses always work
  • Makes stubgen deps depend on Python version; we don't need them in >= 3.9
  • Adds bytewax._bytewax stub file; will need to be re-generated on re-build

@davidselassie davidselassie requested review from whoahbot and removed request for whoahbot January 12, 2024 23:00
stubgen.py Outdated
children = [
children = []
if "__new__" in cls.__dict__:
new = _stub_new(ctx.new_scope("__new__"), cls)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not seeing the correct signature for any of the rust-based classes after this change. Adding the stub for __init__ with the same signature as the newly-added __new__ stub fixed it for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like there's something up with pylsp or Jedi for which only overriding __new__ does not cause the signature for the class to show correctly. I changed the stubgen to "rewrite" the signature for __new__ to __init__ which does display correctly in pylsp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the better way to think about this is: every class defined in Python's signature is derived from it's __init__. Native classes have a way of defining it separately. But since we're translating from native to Python (the stub), we need to move that information from the class itself to the __init__.

@davidselassie davidselassie merged commit 41d505e into main Jan 17, 2024
30 checks passed
@davidselassie davidselassie deleted the stubgen branch January 17, 2024 18:21
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.

None yet

2 participants