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

fix type in Parameter type check #1500

Merged
merged 1 commit into from
Jun 11, 2020
Merged

Conversation

joelberkeley-secondmind
Copy link
Contributor

fixes a minor mistake in the types

@joelberkeley-secondmind joelberkeley-secondmind added this to Bugfix in progress in Open bugs via automation Jun 9, 2020
@codecov
Copy link

codecov bot commented Jun 9, 2020

Codecov Report

Merging #1500 into develop will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1500   +/-   ##
========================================
  Coverage    95.25%   95.25%           
========================================
  Files           82       82           
  Lines         3752     3752           
========================================
  Hits          3574     3574           
  Misses         178      178           
Impacted Files Coverage Δ
gpflow/base.py 92.40% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9e125e...d1e5603. Read the comment docs.

Copy link
Member

@st-- st-- left a 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
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Member

@st-- st-- Jun 10, 2020

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).

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@joelberkeley-secondmind
Copy link
Contributor Author

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?

you mean like ...?

class Module(tf.Module):
    @property
    def parameters(self) -> Tuple["Parameter", ...]:
        return tuple(self._flatten(predicate=lambda o: isinstance(o, Parameter)))

i'm not fussed either way really

@st-- st-- requested a review from awav June 10, 2020 16:40
@joelberkeley-secondmind joelberkeley-secondmind merged commit 7db2276 into develop Jun 11, 2020
Open bugs automation moved this from Bugfix in progress to Resolved Jun 11, 2020
@joelberkeley-secondmind joelberkeley-secondmind deleted the joelb/fix-type branch June 11, 2020 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Open bugs
  
Resolved
Development

Successfully merging this pull request may close these issues.

None yet

2 participants