-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add return-type to public functions, mostly tests part 4 #7645
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
base: main
Are you sure you want to change the base?
Conversation
No change in the effective code. A batch of ~50 files. Modified files pass ruff check --select=ANN201 Partially implements quantumlib#4393
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7645 +/- ##
==========================================
- Coverage 99.56% 99.37% -0.20%
==========================================
Files 1088 1078 -10
Lines 96083 96075 -8
==========================================
- Hits 95667 95472 -195
- Misses 416 603 +187 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
A few drive-by comments.
@@ -217,7 +217,7 @@ def __init__(self, *args, **kwargs) -> None: | |||
super().__init__(*args, **kwargs) | |||
self._memo: dict[Any, dict] = {} | |||
|
|||
def default(self, o): | |||
def default(self, o) -> Any: |
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.
It seems that maybe we could be more specific. Perhaps something like
def default(self, o) -> bool | list[Any] | dict[str, Any]:
...
might work. Maybe one could be even more specific?
Note 1: It is useful to know that if the return type isn't a bool then it's something one can iterate over, and that if it's not a list, then we can iterate over its keys and rely on them being strings.
Note 2: A better opportunity to engineer neat narrow type annotations for these functions is unlikely to materialize in future.
def measurement_key_obj(val: Any, default: Any = RaiseTypeErrorIfNotProvided): | ||
def measurement_key_obj( | ||
val: Any, default: TDefault = RaiseTypeErrorIfNotProvided | ||
) -> cirq.MeasurementKey | TDefault: |
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 this function never returns the type TDefault
of default
, so it would be nice not to have to deal with the alternative at the callsites. It looks like type inference failure in
if default is not RaiseTypeErrorIfNotProvided:
return default
Is there a way to explain to mypy better what's actually going on?
@@ -278,7 +284,7 @@ def is_measurement(val: Any) -> bool: | |||
return keys is not NotImplemented and bool(keys) | |||
|
|||
|
|||
def with_measurement_key_mapping(val: Any, key_map: Mapping[str, str]): | |||
def with_measurement_key_mapping(val: Any, key_map: Mapping[str, str]) -> Any: |
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 we do better than Any
here?
Add return-type to public functions, mostly tests part 4
No change in the effective code. A batch of ~50 files.
Modified files pass ruff check --select=ANN201
Partially implements #4393