-
Notifications
You must be signed in to change notification settings - Fork 14
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 hint sybil/example.py #78
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
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.
I think
mypy
doesn't like checking truthiness of a function: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.
Function "evaluator" could always be true in boolean context
is a pretty crappy message :-(Do you have a link to the mypy docs on what it's sad about here?
The change is needlessly wordy and makes me sad about appeasing mypy's inadequacies :-(
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.
The error was related to https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-function-isn-t-used-in-boolean-context-truthy-function, because
self.document.evaluator
was typed as anEvaluator
.I have changed it to be correctly typed as an
Optional[Evaluator]
, and therefore been able to revert the change which made you sad.That said, we will hit into related problems with
self.document.evaluator
later, asmypy
does not allow assigning to a method:I think that in order to satisfy
mypy
, we will either have to addtype: ignore
s (which I try to avoid, where possible), or changedocument
to be more complex in some ways (likely having another variable to track whether theevaluator
should be used).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.
That "can't assign to a method" feels like a straight up bug in mypy, no?
I'm guessing this problem has come up with other folks attempting to add type hints to existing code of this type?
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'm not sure what that means
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.
There are many discussions on this - with many people wanting
mypy
to support assigning to a method. See python/mypy#708 for an example.I do not get the impression that very soon there will me a
mypy
change to accommodate. You can even see an issue raised by me in 2018 when I wanted to assign to a method precisely as described in the Python documentation: python/mypy#5062 (comment).In a follow-up PR, I think we will have to decide either to change
document
, to add atype: ignore
, or to ignore allmethod-assign
errors.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.
Can this check be disabled in mypy's config file? Failing that, how many
type: ignore
comments are we talking about? :sigh: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.
Yes, that's what I meant when I said: "or to ignore all
method-assign
errors.".Any specific
mypy
error code can be ignored inmypy
's config file.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.
Okay, let's do that... Might be worth getting a branch going that has mypy turned on and rebase that onto master as more PRs land.
(ie: just the CI, so we know where we're at and what config we'll be using...)
That said, how hard would it be to use pyright instead of mypy? I think @hynek has had some success with this?
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.
@cjw296 I'm happy to do those tasks. I think they're best as follow-ups, as this change doesn't yet hit the problem:
mypy
to CI, withpypyoject.toml
level ignores for files which are not yet compliantmethod-assign
error. From this conversation, most likely by globally ignoring that error type. I will look into that further in the follow-up, in case there are complications I have not considered here.pyright
(potentially as a replacement formypy
). I will say that in my own projects, I use bothpyright
andmypy
, and I have found roughly equal numbers of annoyances. I like having both as, despite annoyances, they each have caught a few bugs that the other has not.