Skip to content

Add typing stub#50

Merged
djc merged 4 commits intodjc:mainfrom
KianKhadempour:main
Sep 20, 2024
Merged

Add typing stub#50
djc merged 4 commits intodjc:mainfrom
KianKhadempour:main

Conversation

@KianKhadempour
Copy link
Copy Markdown
Contributor

First off, I'd like to say that I greatly admire this project and I'd like to help out if possible (I have other things going on but I'll try). That being said, here is my first (of hopefully more than one) PR:

Typing is always a great thing to have in a Python package, especially since the types passed to these functions need to be pretty accurate or things could go wrong. I tried my best to re-create the types faithfully, but there are a few parts that I need help on (in order of appearance):

  1. Should TrustAnchor be included? It is annotated as #[pyclass], but it isn't included in the #[pymodule] function. I'm not that familiar with PYO3 so I'll leave that up to you.
  2. I feel like the TLSError class is incomplete, but I can't figure out what to add. Maybe documentation?
  3. In the ClientConnection.read_tls and similar methods, the Rust implementation takes a &[u8]. I put list[int] as the Python version of this, but I'm not sure if this is right. Maybe it should be a tuple[int]? Maybe this method shouldn't exist at all in the stub?
  4. ClientConfig.__new__ and ServerConfig.__new__ take two arguments that I'm not sure to annotate:
    a. Iterable[TrustAnchor | str | bytes] | None or Iterable[TrustAnchor] | Iterable[str] | Iterable[bytes] | None?
    b. Iterable[str | bytes] or Iterable[str] | Iterable[bytes]?

Thanks for considering this PR; I look forward to your feedback.

Comment thread pyrtls.pyi
Comment thread pyrtls.pyi Outdated
Comment thread pyrtls.pyi Outdated
Comment thread pyrtls.pyi Outdated
@djc
Copy link
Copy Markdown
Owner

djc commented Sep 16, 2024

First external PR, thanks for contributing!!

Comment thread pyrtls.pyi
Comment thread pyrtls.pyi
Comment thread pyrtls.pyi
Comment thread pyrtls.pyi Outdated
Comment thread pyrtls.pyi
Comment thread pyrtls.pyi
Comment thread pyrtls.pyi Outdated
KianKhadempour and others added 3 commits September 18, 2024 04:38
- writeable -> writable
- list[int] -> bytes
- bytes before str in type signature
@djc
Copy link
Copy Markdown
Owner

djc commented Sep 18, 2024

Are you aware of https://github.com/MusicalNinjas/pyo3-stubgen? Might be interesting.

@KianKhadempour
Copy link
Copy Markdown
Contributor Author

I'll check it out. Having .pyi files built automatically with CI would be much better since then they'd never get out of sync with the actual code.

@KianKhadempour
Copy link
Copy Markdown
Contributor Author

Looks like our requires-python >= 3.7 doesn't work with pyo3-stubgen's requires-python >= 3.8 (speaking of which, Python 3.7 is out of support and 3.8 is falling out at the end of October, so it might be time to move on from those versions).

pyo3-stubgen also has the following limitations:

  • Only works on functions.
  • We'd have to type the generated stubs ourselves, as it doesn't do that automatically.

There is the pyo3-stub-gen crate, which seemed promising but was unable to work because it depends on an older version of pyo3.

@djc djc merged commit d3f6551 into djc:main Sep 20, 2024
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