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

Provide Type Annotations (PEP 484) #14

Open
4 of 6 tasks
samylovma opened this issue Sep 23, 2023 · 9 comments
Open
4 of 6 tasks

Provide Type Annotations (PEP 484) #14

samylovma opened this issue Sep 23, 2023 · 9 comments

Comments

@samylovma
Copy link
Contributor

samylovma commented Sep 23, 2023

Reasons

  • Improving developer experience with this library.
  • Possibility to use static type analysis for the code base.

Introduction of Type Annotations

References

@spookylukey
Copy link
Contributor

spookylukey commented Sep 24, 2023

Hi @Samylov-Mikhail thanks for opening the issue!

In general I think there is a good chance that type annotations and mypy checking (or maybe pyright) could be useful in this library, although I think they are not always helpful. It depends what you are using them for and the nature of the library.

In this case I've got a few questions for you:

  • what is your particular interest in fluent-compiler?
  • which of the different uses of type hints concern you?
  • Are you thinking from the perspective of a user of fluent-compiler or a prospective maintainer on the code base? This question is quite important, because the user interface of fluent-compiler that I expect is actually in use is very small - basically https://fluent-compiler.readthedocs.io/en/latest/api/compiler.html and a few other bits and pieces. This is the interface that django-ftl uses, for example, and no-one using django-ftl uses fluent-compiler directly. I currently have extremely little info on who else is using this library directly, but I expect it is very few people. The maintainer perspective on types is probably very different.

All of the above questions are another way of asking "what problem are you hoping to solve?"

@spookylukey
Copy link
Contributor

Sorry, I didn't mean to close!

@spookylukey spookylukey reopened this Sep 25, 2023
@samylovma
Copy link
Contributor Author

samylovma commented Sep 25, 2023

Hi, Luke. Thank you for the quick feedback!

What is your particular interest in fluent-compiler?

I'm using fluent-compiler directly (not using django-ftl) in my chat bot application. I have chosen this library because of better maintenance compared to fluent.runtime.

Which of the different uses of type hints concern you?

Mostly static type checking to detect issues with my use of the library.

Are you thinking from the perspective of a user of fluent-compiler or a prospective maintainer on the code base?

Mostly I thinking from the perspective of a user. Type hints can improve UX for developers like me who use fluent-runtime directly.

Since the library is stable, I guess type hints won't be enemies of a prospective maintainer. Otherwise we can create third-party type stubs.

Benefits of type hints for a maintainer:

  • specifying the interface of the library;
  • using static type checkers to find issues.

Have you considered pyright instead of mypy?

Seriously no. I have no real experience with pyright. In mypy compared to pyright I like cool documentation and large community.

What kind of approach would you be thinking of to add types? Have you looked at https://github.com/Instagram/MonkeyType or similar?

Since the codebase isn't so large I'm thinking of adding type hints manually. But I don't mind trying automated tools for that.

@spookylukey
Copy link
Contributor

That's sounds great - as long as you are a user and looking at changes that would benefit you as a user, that's great. My only concern is adding lots of stuff that may or may not be helpful. As a maintainer, there are definitely bits I know of that could benefit from types, but there are also bits that would be very hard to type and I wouldn't want you getting stuck with something too ambitious!

@samylovma
Copy link
Contributor Author

Thank you for your rationality, @spookylukey!
I suggest just starting to integrate mypy and add type hints gradually where it's real helpful.
What do you think about this approach?

@spookylukey
Copy link
Contributor

Thank you for your rationality, @spookylukey! I suggest just starting to integrate mypy and add type hints gradually where it's real helpful. What do you think about this approach?

That sounds fine to me - thanks in advance!

@samylovma
Copy link
Contributor Author

samylovma commented Sep 26, 2023

Good!

So I have a plan:

  1. Do some refactoring before the next step. (I will create an issue or a PR for every point.)
  2. Get mypy to run successfully.
  3. Add type hints for:
    • ...

P. S. This plan can be updated.

UPDATE: This plan moved to the body of this issue.

@spookylukey
Copy link
Contributor

Remove the ast_compat module.

Is there a reason for this? What particularly problem would removing it solve? The Python AST is not stable, and I expect it will continue to have changes, and having a single place to accommodate those changes has been very useful in the past.

@samylovma
Copy link
Contributor Author

@spookylukey, I've created the issue #19 for that.

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