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

Fix error message for incorrect calls with unlock_instance #1044

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

nikfilippas
Copy link
Contributor

While reviewing baryons_v3 I realized I had not implemented a fallback mechanism in case the input of unlock_instance was nonsense. This resulted to a very cryptic error message when

  • users called the decorated function with wrong arguments
  • developers specified an incorrect number in argv
@ccl.unlock_instance(argv=1)
def func(item, pk, a0=0, *, a1=None, a2):
    return

func()  # wrong call to function

Traceback (most recent call last):

  Cell In[3], line 1
    func()

  File ~/CCL/pyccl/base.py:419 in wrapper
    arg = args[argv] if size > argv else list(kwargs.values())[argv-size]  # noqa

IndexError: list index out of range

This PR uses inspect.signature.bind which mimics the default Python behavior for incorrect function calls. The main difference with what is currently in master is that we now have to specify the name of the unlocked argument, rather than the argv. As an added bonus, it checks on import if the name actually exists, or if the developer has made a typo. The previous version would only complain at runtime.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 4492834264

  • 12 of 12 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 97.859%

Totals Coverage Status
Change from base Build 4477013263: 0.002%
Covered Lines: 5484
Relevant Lines: 5604

💛 - Coveralls

pyccl/bcm.py Show resolved Hide resolved
pyccl/base.py Show resolved Hide resolved
@nikfilippas nikfilippas merged commit bccfc88 into master Mar 23, 2023
@nikfilippas nikfilippas deleted the fix_unlock_instance_errormessage branch March 23, 2023 14:30
@nikfilippas nikfilippas mentioned this pull request Apr 1, 2023
27 tasks
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.

3 participants