Skip to content

fix: exports crash without optional deps, Vector.like() type safety, and docstring corrections#716

Draft
henryiii wants to merge 2 commits into
mainfrom
fix/exports-and-docstrings
Draft

fix: exports crash without optional deps, Vector.like() type safety, and docstring corrections#716
henryiii wants to merge 2 commits into
mainfrom
fix/exports-and-docstrings

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Summary

Part of #711

  • Fix from vector import * crash without optional deps (src/vector/__init__.py): All optional names (MomentumSympy2D/3D/4D, VectorSympy2D/3D/4D, awkward_transform) are now defined as None in the except ImportError branches, so star-imports no longer raise AttributeError when sympy or awkward is absent. __dir__() is also updated to filter these names out when the corresponding dependency is missing.
  • Fix Vector.like() to raise TypeError for non-vector arguments (src/vector/_methods.py): The else branch now only triggers for Vector4D; anything else raises TypeError (matching the style of dim()).
  • Docstring corrections (src/vector/_methods.py):
    • eta property: removed copy-paste from theta ("in radians, always between 0 and π"); replaced with correct pseudorapidity description including the formula η = −ln tan(θ/2).
    • rotate_euler: Tait-Bryan list was a duplicate of the proper Euler list; corrected to "xzy", "xyz", "yxz", "yzx", "zyx", "zxy" (verified against _compute/spatial/rotate_euler.py).
    • MomentumProtocolLorentz.E: fixed typo "synonyor" → "synonym for".
    • MomentumProtocolLorentz.E2: fixed broken cross-ref :attr:VectorProtocolLorent2 → `:attr:`VectorProtocolLorentz.t2.
    • to_pxpythetamass: corrected "$energy$" → "$mass$" in first-line description.
    • to_ptphietamass: corrected "$\theta$" → "$\eta$" in first-line description.
    • Vector2D.to_Vector4D and Vector3D.to_Vector4D error messages: "At most one longitudinal coordinate" → "temporal" for the temporal over-specification check.

Test plan

  • test_star_import_without_optional_deps: subprocess test that blocks sympy via a find_spec meta-path finder, then verifies from vector import * succeeds and sympy names are absent from dir(vector)
  • test_like_non_vector_raises: verifies v.like(5) raises TypeError
  • test_to_vector4d_temporal_error_message: verifies the error message says "temporal" for both Vector2D.to_Vector4D and Vector3D.to_Vector4D
  • 814 existing tests pass, 3 skipped (dask-awkward, optree, jax — all pre-existing)
  • All docstring doctests pass (--doctest-plus src/vector/; only pre-existing _pytree.py optree failure)
  • prek -a --quiet passes cleanly

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.23%. Comparing base (d9ef1db) to head (4b97068).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #716      +/-   ##
==========================================
+ Coverage   87.16%   87.23%   +0.06%     
==========================================
  Files          96       96              
  Lines       11199    11200       +1     
==========================================
+ Hits         9762     9770       +8     
+ Misses       1437     1430       -7     

☔ View full report in Codecov by Harness.
📢 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.

…and docstring corrections

- Define all optional-dep names (MomentumSympy2D/3D/4D, VectorSympy2D/3D/4D,
  awkward_transform) as None in the except branches so `from vector import *`
  no longer raises AttributeError when sympy or awkward is absent
- Fix __dir__() to filter out sympy and awkward names when those deps are missing
- Make Vector.like() raise TypeError for non-vector arguments instead of
  silently calling to_Vector4D()
- Fix eta docstring: remove copy-paste from theta (no longer says "in radians,
  always between 0 and pi"); add correct pseudorapidity formula
- Fix rotate_euler docstring: Tait-Bryan list was a copy of the Euler list;
  corrected to xzy/xyz/yxz/yzx/zyx/zxy per compute file
- Fix MomentumProtocolLorentz.E docstring typo ("synonyor" -> "synonym for")
- Fix MomentumProtocolLorentz.E2 broken cross-ref (VectorProtocolLorent2 ->
  VectorProtocolLorentz.t2)
- Fix to_pxpythetamass docstring: "$energy$" -> "$mass$"
- Fix to_ptphietamass docstring: "$\theta$" -> "$\eta$"
- Fix to_Vector4D error messages in Vector2D and Vector3D: "longitudinal
  coordinate" -> "temporal coordinate" for temporal over-specification error
- Add tests for all of the above

Assisted-by: ClaudeCode:claude-sonnet-4-6
@henryiii henryiii force-pushed the fix/exports-and-docstrings branch from 6d83076 to c6f0644 Compare June 16, 2026 04:04
… no-cover

The star-import fix's regression test runs in a subprocess, so its coverage
of the optional-dependency fallbacks is not captured by pytest-cov. Mark those
import-time except branches as no-cover and add an in-process test for the
__dir__ name-exclusion logic.

Assisted-by: ClaudeCode:claude-opus-4.8
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