Skip to content

Conversation

@ycexiao
Copy link
Contributor

@ycexiao ycexiao commented Aug 4, 2025

What problem does this PR address?

Closes #72

Use ValueError instead of TypeError for incorrect calculations.

What should the reviewer(s) do?

Please check the modifications.

@codecov
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.05%. Comparing base (b94a3a9) to head (2c448e0).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #129   +/-   ##
=======================================
  Coverage   67.05%   67.05%           
=======================================
  Files          25       25           
  Lines        3160     3160           
=======================================
  Hits         2119     2119           
  Misses       1041     1041           
Files with missing lines Coverage Δ
tests/test_literals.py 99.17% <100.00%> (ø)
tests/test_visitors.py 99.19% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ycexiao ycexiao marked this pull request as ready for review August 4, 2025 19:39
@ycexiao
Copy link
Contributor Author

ycexiao commented Aug 4, 2025

@sbillinge, it's ready for review.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

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

please see comments

self._value = self.operation(*vals)
except Exception as e:
raise ValueError(
"Error evaluating operator '%s' with arguments %s : %s"
Copy link
Contributor

Choose a reason for hiding this comment

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

could we have this as an f-string for greater readability?

self._value = self.operation(*vals)
try:
self._value = self.operation(*vals)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be TypeError maybe? Turning any exception into a valueError may lead to confusion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. After a second thought, I think maybe we should not modify it at all.

The test-case-bad uses np.add but only gives it one argument. We want to use ValueError instead of TypeError in this bad case, because the input type is correct. But we can't customize all possible Errors that a user might encounter in their practice. I think the best approach is to leave the original error message and let the user see where they are wrong directly.

So, I think it is better to raise whatever the external function raises. In this case, we can close #72 as not planned.

@sbillinge
Copy link
Contributor

I read the original issue and it was that get_value returned TypeError instead of ValueError when it op._value was set to None, so it looks to me that you may be fixing the problem incorrectly? Not sure, but I would expect to see something like

if self._value is None:
    raise ValueError

somewhere inside getValue()?

@ycexiao
Copy link
Contributor Author

ycexiao commented Aug 5, 2025

I read the original issue and it was that get_value returned TypeError instead of ValueError when it op._value was set to None

Oh, I see. I thought we need fix both TypeError

@ycexiao
Copy link
Contributor Author

ycexiao commented Aug 5, 2025

Closed as the issue will be addressed in another cleaner PR.

@ycexiao ycexiao closed this Aug 5, 2025
@ycexiao ycexiao deleted the use-valuerror branch August 5, 2025 16:37
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.

Modify TypeError to ValueError for getValue() when op._value = None

2 participants