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

Type definitions #138

Open
silverwind opened this issue Oct 2, 2024 · 4 comments
Open

Type definitions #138

silverwind opened this issue Oct 2, 2024 · 4 comments

Comments

@silverwind
Copy link

silverwind commented Oct 2, 2024

Could/Does this module provide type definitions?. It looks like type checkers like pyright can not find any types:

image
@sarayourfriend
Copy link
Collaborator

Pook does not export types, but I'd welcome PRs to that end ❤️

@sarayourfriend
Copy link
Collaborator

@silverwind in case you are interested, I've added the baseline stuff for type annotations/checking pook itself in #143. My plan to get pook exporting types is to have the library itself pass type checks, as I'm not interested in maintaining separate stub files if it can possibly be avoided. To get there, I'd like to focus on small PRs that add annotations and checking to a contained section of the code each time (through judicious use of # type: ignore to draw boundaries on imports). I'll spend a little time later coming up with a list of the individual sections for each PR, but if you have any input or feel up to getting a few of those done, let me know. I'll share the list in this issue once I've written it out.

@silverwind
Copy link
Author

silverwind commented Oct 11, 2024

I don't think I can be of much help as I'm just starting to get into typed python. I do have quite a bit of typescript experience though, and in many senses, these type systems look similar, though python's system seems less fledged out, with things like the type statement only being recently added in 3.12.

@sarayourfriend
Copy link
Collaborator

There are some similarities, mostly in that they are both additions over top an otherwise highly dynamic language. TS is structurally typed though, and Python is nominally typed, with structural typing only possible when explicitly using Protocol added in 3.8. For the simplest cases you don't need to worry about these differences. Pook has some areas that should be simpler to contribute types too, I'll let you know if I identify any that might better suited for you, if you're interested.

The biggest thing I've found missing in Python's type system coming from a broader TypeScript background are conditional and mapped types, and that mypy will not auto-cast strings to Literal sometimes.

For what it's worth, the type statement in Python has a very narrow use case, and typically isn't necessary for most code, we get by fine without them, and wouldn't be able to use them in pook anyway, as pook supports all maintained Python versions (so >=3.9 since this week 3.8 went EOL).

The main difficulty with pook will be working around somewhat tedious optional attributes/properties, where things can technically be None, but in practice never will be outside of specific, almost never relevant windows. Also some places where the types seem to indicate the code might be totally wrong (and where I'm not confident the code is actually right anyway!). It will be interesting to see if adding types to pook can be accomplished without introducing too many runtime changes.

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