-
Notifications
You must be signed in to change notification settings - Fork 435
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
fix type in Parameter type check #1500
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1500 +/- ##
========================================
Coverage 95.25% 95.25%
========================================
Files 82 82
Lines 3752 3752
========================================
Hits 3574 3574
Misses 178 178
Continue to review full report at Codecov.
|
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.
Happy with the type changes. Just wondering about the change on line 50: I would normally think re-using code is better than copying it - if you think the _IS_PARAMETER by itself is overkill, maybe just go and remove both of these everywhere?
def _IS_TRAINABLE_PARAMETER(o: Any) -> bool: | ||
return _IS_PARAMETER(o) and o.trainable | ||
def _IS_TRAINABLE_PARAMETER(o: object) -> bool: | ||
return isinstance(o, Parameter) and o.trainable |
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.
What was the motivation behind no longer reusing the _IS_PARAMETER defined above?
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.
mypy doesn't know that _IS_PARAMETER(o) == True
means o
is a Parameter
, and that's needed for o.trainable
to type check. I think mypy special-cases isinstance
so it can work it out from that
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.
if it were possible, i'd also mildly prefer using _IS_PARAMETER
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.
Seems to me like a case where mypy is flawed and it'd be better code leaving it as it had been with a # type: ignore
at the end (and maybe a comment explaining what you wrote above).
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.
mypy's fine. it's a type theory thing afaict. I don't think any language would be able to prove that
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.
at least not without pattern matching
4a35af0
to
9c59829
Compare
you mean like ...?
i'm not fussed either way really |
9c59829
to
d1e5603
Compare
fixes a minor mistake in the types