Skip to content

Fix Basix bugs surfaced by Pyrefly - #1069

Open
jhale wants to merge 1 commit into
jhale/check-with-pyreflyfrom
jhale/fix-pyrefly-errors
Open

jhale wants to merge 1 commit into
jhale/check-with-pyreflyfrom
jhale/fix-pyrefly-errors

Conversation

@jhale

@jhale jhale commented Sep 14, 2026

Copy link
Copy Markdown
Member

Stacked on #1068. Fixes the real bugs Pyrefly surfaced there, shrinking the baseline from 22 to 7.

  • ufl.py: annotate get_tensor_product_representation's base return type (was inferred -> None, tripping a false bad-override on every real subclass); fix a loop variable (e) used after its for loop in create_enriched_element, which was unbound whenever map_type was already given.
  • test_continuity.py: facets rows mixed ndarray and dict as plain lists, so unpacking unioned every variable's type across the row — switched to tuples.
  • test_bernstein.py, test_mappings.py (×2), test_interpolation_between_elements.py: non-exhaustive if/elif chains left a variable possibly unbound; added an else: raise NotImplementedError.
  • test_tensor_products.py: the assertion comparing values1/values2 sat after its for fs in factors loop instead of inside it, so only the last tensor factor was ever checked; moved it in — also unbound if factors was ever empty.
  • test_version.py: import basix._basixcpp directly so it's a statically visible attribute.

The 7 remaining baselined diagnostics are matplotlib/sympy stub artifacts unrelated to Basix's own code (per Pyrefly, mplot3d's Axes return can be None; sympy's third-party stubs don't model Symbol arithmetic against numpy arrays).

Verified: pyrefly check --error-stale-baseline → 0 errors; ruff clean; full pytest coverage for every touched test file plus test_ufl_wrapper.py passes (957 passed, 0 failed).

- ufl.py: annotate get_tensor_product_representation's base return
  type so real overrides stop tripping bad-override; fix a stray
  loop variable used after its loop in create_enriched_element.
- test_continuity.py: facets lists mixed ndarray/dict rows as plain
  lists, unioning every unpacked variable's type; switch to tuples.
- test_bernstein.py, test_mappings.py (x2),
  test_interpolation_between_elements.py: non-exhaustive if/elif
  chains left a variable possibly unbound; add an else raise.
- test_tensor_products.py: the assert comparing values1/values2 sat
  after its loop instead of inside it, so only the last tensor
  factor was ever checked (and values2 was unbound if factors was
  empty); move the assert into the loop.
- test_version.py: import basix._basixcpp directly so it's a
  statically visible attribute.

The 7 remaining baselined diagnostics are matplotlib/sympy stub
artifacts unrelated to Basix's own code.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DufZTv24tYPshRaUq1UBKW
@jhale
jhale added this pull request to stack #1070 September 14, 2026 14:19
@jhale jhale changed the title Fix Basix bugs surfaced by Pyrefly, shrink baseline to 7 Fix Basix bugs surfaced by Pyrefly Sep 14, 2026
@jhale
jhale marked this pull request as ready for review September 14, 2026 14:21
@jhale
jhale requested a review from mscroggs September 14, 2026 14:22
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.

1 participant