Skip to content

Commit

Permalink
Fix recent type check failure in the CI (#6699)
Browse files Browse the repository at this point in the history
Fix failure of the mypy (Type check) job in ci.yml. 
Help mypy detect when optional argument has been provided.

No change in the code function.
  • Loading branch information
pavoljuhas authored Aug 5, 2024
1 parent 7566248 commit 51e8c3d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cirq-core/cirq/experiments/qubit_characterizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes:
The plt.Axes containing the plot.
"""
show_plot = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=(8, 8)) # pragma: no cover
ax.set_ylim((0.0, 1.0)) # pragma: no cover
ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro', label='data', **plot_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/linalg/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def scatter_plot_normalized_kak_interaction_coefficients(
>>> plt.show()
"""
show_plot = not ax
if not ax:
if ax is None:
fig = plt.figure()
ax = cast(mplot3d.axes3d.Axes3D, fig.add_subplot(1, 1, 1, projection='3d'))

Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/vis/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def plot(
is plotted on. ``collection`` is the collection of paths drawn and filled.
"""
show_plot = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(figsize=(8, 8))
original_config = copy.deepcopy(self._config)
self.update_config(**kwargs)
Expand Down Expand Up @@ -413,7 +413,7 @@ def plot(
is plotted on. ``collection`` is the collection of paths drawn and filled.
"""
show_plot = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(figsize=(8, 8))
original_config = copy.deepcopy(self._config)
self.update_config(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/vis/state_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def plot_state_histogram(
The axis that was plotted on.
"""
show_fig = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(1, 1)
if isinstance(data, result.Result):
values = get_state_histogram(data)
Expand Down
4 changes: 2 additions & 2 deletions cirq-google/cirq_google/engine/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def plot_histograms(
ValueError: If the metric values are not single floats.
"""
show_plot = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(1, 1)

if isinstance(keys, str):
Expand Down Expand Up @@ -320,7 +320,7 @@ def plot(
values are not single floats.
"""
show_plot = not fig
if not fig:
if fig is None:
fig = plt.figure()
axs = cast(List[plt.Axes], fig.subplots(1, 2))
self.heatmap(key).plot(axs[0])
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Foo:
...
def plot(self, ax: Optional[plt.Axes]=None, **plot_kwargs: Any) -> plt.Axes:
show_plot = not ax
if not ax:
if ax is None:
fig, ax = plt.subplots(1, 1) # or your favorite figure setup
# Call methods of the ax instance like ax.plot to plot on it.
...
Expand Down Expand Up @@ -81,7 +81,7 @@ class Foo:
def plot(self, axes: Optional[List[plt.Axes]]=None,
**plot_kwargs: Any) -> List[plt.Axes]:
show_plot = not axes
if not axes:
if axes is None:
fig, axes = plt.subplots(1, 2) # or your favorite figure setup
elif len(axes) != 2: # your required number of axes
raise ValueError('your error message')
Expand Down

0 comments on commit 51e8c3d

Please sign in to comment.