Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish type error from name error in pyparser #733

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

akeley98
Copy link
Contributor

Previously, when parse_expr failed to resolve a name to a value, it always reported "undefined variable" errors regardless of whether the cause was due to failing to look up the name in the global/local scope, or due to correctly looking up the name but the value not being a valid type (e.g. the name resolving to a str value). I changed the parser to distinguish these 2 cases in the error message (see the new tests I added to see what I mean).

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 88.00%. Comparing base (2c31b61) to head (206f1e2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_uast.py 68.42% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #733      +/-   ##
==========================================
- Coverage   88.01%   88.00%   -0.01%     
==========================================
  Files          86       86              
  Lines       20928    20965      +37     
==========================================
+ Hits        18419    18450      +31     
- Misses       2509     2515       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akeley98
Copy link
Contributor Author

Not sure if I'm understanding codecov correctly, but it's mad that the new tests are not themselves tested?

Copy link
Member

@yamaguchi1024 yamaguchi1024 left a comment

Choose a reason for hiding this comment

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

Aren't you forgetting @proc on function definitions in the test?

@akeley98
Copy link
Contributor Author

I was emulating the existing tests in test_uast.py which lack @proc

Copy link
Member

@yamaguchi1024 yamaguchi1024 left a comment

Choose a reason for hiding this comment

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

Wait nvm I didn't see the rest of the test. LGTM. Can you double check that tests you added are actually run by pytest?

@akeley98
Copy link
Contributor Author

Yes, they are

mantissa@MantissaAmpere:~/Documents/exo$ pytest -v tests/test_uast.py                       
=================================== test session starts ====================================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/mantissa/Documents/exo
configfile: pyproject.toml
collected 6 items                                                                          

tests/test_uast.py::test_conv1d PASSED                                               [ 16%]
tests/test_uast.py::test_unary_neg PASSED                                            [ 33%]
tests/test_uast.py::test_alloc_nest PASSED                                           [ 50%]
tests/test_uast.py::test_variable_lookup_positive PASSED                             [ 66%]
tests/test_uast.py::test_variable_lookup_type_error PASSED                           [ 83%]
tests/test_uast.py::test_variable_lookup_name_error PASSED                           [100%]

===================================== warnings summary =====================================
tests/conftest.py:2
  /home/mantissa/Documents/exo/tests/conftest.py:2: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    import distutils.spawn

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================== 6 passed, 1 warning in 0.06s ===============================

Looking at the report, it is just flagging the test functions that are passed to the uast parser (since the funcs are defined only for their AST, they are not actually executed).

@akeley98 akeley98 merged commit cd5f597 into main Oct 23, 2024
7 of 9 checks passed
@akeley98 akeley98 deleted the akeley98/uast_type_error branch October 23, 2024 17:05
yamaguchi1024 pushed a commit that referenced this pull request Oct 23, 2024
Distinguish undefined variable error from type error in UAST parser
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.

2 participants