Skip to content

fix(bigframes): fix mypy errors in _magics.py related to get_ipython - #17979

Merged
shuoweil merged 1 commit into
mainfrom
fix-mypy-ipython-none-check-13181547226489082485
Aug 3, 2026
Merged

fix(bigframes): fix mypy errors in _magics.py related to get_ipython#17979
shuoweil merged 1 commit into
mainfrom
fix-mypy-ipython-none-check-13181547226489082485

Conversation

@tswast

@tswast tswast commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fixes mypy error in bigframes/_magics.py caused by get_ipython() potentially returning None.

The issue was seen as:

nox > mypy bigframes tests/system tests/unit --check-untyped-defs --explicit-package-bases '--exclude="^third_party"'
bigframes/_magics.py:44: error: Item "None" of "InteractiveShell | None" has no attribute "user_ns"  [union-attr]
bigframes/_magics.py:49: error: Item "None" of "InteractiveShell | None" has no attribute "push"  [union-attr]

Resolved by adding a guard clause that checks if ipython is None, which then raises a RuntimeError, naturally helping mypy narrow down the types.


PR created automatically by Jules for task 13181547226489082485 started by @tswast

Added a None check for `ipython` retrieved using `get_ipython()` in `bigframes/_magics.py` to prevent mypy `union-attr` errors when accessing `ipython.user_ns` and `ipython.push`. If `ipython` is None, a `RuntimeError` is raised indicating that the magic must be run in an IPython environment.

Co-authored-by: tswast <247555+tswast@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@tswast
tswast requested review from a team as code owners August 3, 2026 16:58
@tswast
tswast requested review from shuoweil and removed request for a team August 3, 2026 16:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the _cell_magic function in packages/bigframes/bigframes/_magics.py to check if the IPython environment is available. If get_ipython() returns None, it now raises a RuntimeError indicating that the BigQuery magic must be run in an IPython environment. There are no review comments, and I have no feedback to provide.

@shuoweil
shuoweil merged commit 24d955e into main Aug 3, 2026
42 of 43 checks passed
@shuoweil
shuoweil deleted the fix-mypy-ipython-none-check-13181547226489082485 branch August 3, 2026 18:09
tswast pushed a commit that referenced this pull request Aug 3, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.47.0](bigframes-v2.46.0...bigframes-v2.47.0)
(2026-08-03)


### Features

* **bigframes:** add ai.embed and ai.similarity to bigquery accessor
([#17927](#17927))
([2d1372b](2d1372b))


### Bug Fixes

* **bigframes:** fix mypy errors in _magics.py related to get_ipython
([#17979](#17979))
([24d955e](24d955e))
* bump brace-expansion from 5.0.6 to 5.0.7 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17794](#17794))
([2df1bb5](2df1bb5))
* bump fast-uri from 3.1.1 to 3.1.4 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17828](#17828))
([8ce495a](8ce495a))
* bump hono from 4.12.16 to 4.12.31 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17829](#17829))
([6d6fa39](6d6fa39))
* bump immutable from 5.1.7 to 5.1.9 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17830](#17830))
([6abb1da](6abb1da))
* bump postcss from 8.5.14 to 8.5.23 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17908](#17908))
([e68eb8f](e68eb8f))
* bump tar from 7.5.16 to 7.5.20 in
/packages/bigframes/bigframes/display/table_widget_angular
([#17793](#17793))
([3502d41](3502d41))
* require Protobuf 6.33.5+
([#17743](#17743))
([d267342](d267342))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants