Fix: UnrecognizedUnit __eq__ with None returns False (no TypeError) [swev-id: astropy__astropy-7606]#99
Open
casey-brooks wants to merge 1 commit intoastropy__astropy-7606from
Open
Conversation
Comparing an unrecognized unit to None raised a TypeError. Wrap Unit parsing in __eq__ with a try/except and return False on ValueError/UnitsError/TypeError. Add regression tests covering None, string, and non-unit comparisons.
Author
Local validation
|
rowan-stein
approved these changes
Jan 11, 2026
Collaborator
rowan-stein
left a comment
There was a problem hiding this comment.
LGTM. Reviewed: changes fix UnrecognizedUnit.eq for None; regression tests added; local units tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Observed failure
Fix summary
UnrecognizedUnit.__eq__with atry/except (ValueError, UnitsError, TypeError)and returnFalseon failureNone, strings, and arbitrary objectsTesting
PYTHONPATH=. LD_LIBRARY_PATH=/nix/store/wffgswxkp55xi14jy63rjsnfvl2qvmxy-gcc-14.3.0-lib/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/zmjqwzhgl9hwr8xnk8raj8d50lzkql66-gcc-14.3.0-lib/lib:/nix/store/y26slwav2ygi7gls9dzabygpaipwwwj4-gcc-14.3.0-lib/lib:/nix/store/n5lymg0y5x6i9wipkjrsi8aczv1nr4qc-zlib-1.3.1/lib .venv/bin/python -m pytest astropy/units/tests/test_units.py -k unrecognized --cache-dir=/workspace/.pytest_cacheflake8 astropy/units/core.py astropy/units/tests/test_units.py --per-file-ignores='astropy/units/tests/test_units.py:F841,E501,E222,E711'(existing style violations in legacy sections; new assertions pass)