Skip to content

EvenQ, OddQ, PrimeQ: return False for non-atoms instead of crashing - #1992

Open
tombouctou wants to merge 1 commit into
Mathics3:masterfrom
tombouctou:fix-evenq-oddq-primeq-nonatom
Open

tombouctou wants to merge 1 commit into
Mathics3:masterfrom
tombouctou:fix-evenq-oddq-primeq-nonatom

Conversation

@tombouctou

Copy link
Copy Markdown

Since #1934, only atoms have an int_value property, but EvenQ.test, OddQ.test and PrimeQ.eval still read n.int_value directly. Any non-atomic argument now crashes the interpreter:

In[1]:= EvenQ[f[1]]
AttributeError: 'Expression' object has no attribute 'int_value'

The same crash happens in pattern tests such as MatchQ[f[1], _?EvenQ] or Cases[{2, f[2], 3}, _?OddQ]. On 10.0.1 these return False (and {3}).

This PR uses get_int_value() from mathics.core.number, which returns None for anything without an integer value.

Tests: new cases in test/builtin/test_testing_expressions.py (test_numerical_properties). They fail on current master and pass with this change.

🤖 Generated with Claude Code

Since Mathics3#1934 only atoms have an int_value property, so EvenQ[f[1]] and
patterns such as _?EvenQ raised AttributeError on any expression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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