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

[nnx] flaglib add get overloads #3582

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

cgarciae
Copy link
Collaborator

What does this PR do?

Adds typing overloads for flagslib.get.

@codecov-commenter
Copy link

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (008c3cc) 56.32% compared to head (2eebcc0) 56.33%.

Files Patch % Lines
flax/experimental/nnx/nnx/flaglib.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3582      +/-   ##
==========================================
+ Coverage   56.32%   56.33%   +0.01%     
==========================================
  Files         100      100              
  Lines       11951    11959       +8     
==========================================
+ Hits         6731     6737       +6     
- Misses       5220     5222       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

...

@tp.overload
def get(self, name: str, default: A) -> A:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the right return type is A | Any, because the value stored in the context is not guaranteed to be of type A.

Comment on lines +71 to +74
def get(self, name: str, default: A) -> A:
...

def get(self, name: str, default: A = None) -> A | None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need a separate overload if the method signatures are the same?

Copy link
Member

@superbobry superbobry Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last non-@overloaded definition is not used by type checkers, so this LGTM.

@copybara-service copybara-service bot merged commit cff22d3 into main Jan 3, 2024
21 checks passed
@copybara-service copybara-service bot deleted the nnx-flagslib-add-get-overloads branch January 3, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants