Skip to content

Conversation

pavoljuhas
Copy link
Collaborator

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

No change in the effective code.  A batch of ~50 files.

Modified files pass  ruff check --select=ANN201

Partially implements quantumlib#4393
@pavoljuhas pavoljuhas requested review from vtomole and a team as code owners September 10, 2025 06:21
@pavoljuhas pavoljuhas requested a review from viathor September 10, 2025 06:21
@github-actions github-actions bot added the size: XL lines changed >1000 label Sep 10, 2025
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.37%. Comparing base (9f3b2c5) to head (88f4ca2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@viathor viathor left a 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:
Copy link
Collaborator

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:
Copy link
Collaborator

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:
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants