-
Notifications
You must be signed in to change notification settings - Fork 32
RFC: Adding a bunch more type annotations from pyrefly #50
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it required by Pyrefly to annotate the types of all variables?
In my opinion, annotations like
nvsfr: int = len(vsfr_ids)ortarget_date: str = r.unpack_string()make the code feel overloaded - these types are trivial for a reader to infer and should also be easy for a static analyzer to deduce.I do like annotations such as
ret: list[int] = []and annotations in function arguments.Even if these annotations are mandatory for Pyrefly, I’m open to including them in this repo if you find them useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are levels of checking and annotation you can tune; there were some variables that didn't appear to need type annoations. 🤷🏻
I agree that some things are trivial to infer -
len(thing) -> int- and that function argument and return value annotations are useful. It seems like the philosophy of behind pyre and pyrefly is to annotate everything (handy when your IDE can complain when you stuff the wrong data type into a variable) since python isn't strictly typed, so requiring type annotations is a way to make you be more careful.I think you can close this PR, or just keep it for discussion about type checking and annotations in general; I'll do a cleaner one to ensure that as many functions as possible have annotated arguments and return values, at least where it's not ugly.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pyrefly infers and displays types for local variables mostly as a development aid, they don't have to be added to the code unless it helps with clarity.
It's probably a good idea to add annotations for function params and returns though, and Pyrefly will help infer the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pyrefly also doesn't guess the annotation properly depending on how you import something (IMO).
the inferred type of now is
datetime, but thendatetime.nowdoesn't exist. If was to sayfrom datetime import datetimethennow:datetime = datetime.now()would do what I want, but since I saidimport datetimeI'd have expected pyrefly to infernow:datetime.datetime.