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

Fixed Improper Method Call: __exit__() #2402

Merged
merged 4 commits into from Nov 15, 2023

Conversation

fazledyn-or
Copy link
Contributor

Description

While triaging your project, our bug fixing tool generated the following message(s)-

In file: openpmd_hdf5.py, class: HDF5Reader, there is a special method __exit__ that contains an unexpected number of parameters. Each call to this method will result in a TypeError. iCR suggested that special methods should have an expected number of parameters. More infomation can be found in the Python documentation on the various special method.

Proof of Concept / Explanation

Let's take the code example below. We're using a sample HDF5 file from this link.

from plasmapy.plasma.sources.openpmd_hdf5 import HDF5Reader

hdf5 = "example.h5"
print("Before entering context")
with HDF5Reader(hdf5) as f:
    print("Inside the context")
print("After exiting context")

Output:

(env) ataf@openrefactory:~/BFAS/Source/PlasmaPy$ python3 _test.py 
Before entering context
Inside the context
Traceback (most recent call last):
  File "/home/ataf/BFAS/Source/PlasmaPy/_test.py", line 5, in <module>
    with HDF5Reader(hdf5) as f:
TypeError: HDF5Reader.__exit__() takes 1 positional argument but 4 were given

However, after changing the __exit__ method, we get the following output -

(env) ataf@openrefactory:~/BFAS/Source/PlasmaPy$ python3 _test.py 
Before entering context
Inside the context
After exiting context

If the HDF5Reader class is to be used as a context manager, you must change the __exit__ method as suggested in this PR. Otherwise, you can delete both __enter__ and __exit__ methods to avoid confusion.

Changes

  • Modified the method signature of __exit__ according to documentation

Previously Found & Fixed

CLA Requirements

This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.

All contributed commits are already automatically signed off.

The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).
- Git Commit SignOff documentation

Sponsorship and Support

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed – to improve global software supply chain security.

The bug is found by running the Intelligent Code Repair (iCR) tool by OpenRefactory and then manually triaging the results.

Signed-off-by: fazledyn-or <ataf@openrefactory.com>
@fazledyn-or fazledyn-or requested a review from a team as a code owner November 14, 2023 07:15
@fazledyn-or fazledyn-or requested review from namurphy and removed request for a team November 14, 2023 07:15
Copy link

Thank you for submitting a pull request (PR) to PlasmaPy! ✨ The future of the project depends on contributors like you, so we deeply appreciate it! 🌱

Our contributor guide has information on:

The bottom of this page shows several checks that are run for every PR. Don't worry if something broke! We break stuff all the time. 😺 Click on "Details" to learn why a check didn't pass. Please also feel free to ask for help. We do that all the time as well. 🌸 You can find us in our chat room or weekly community meeting & office hours. Here are some tips:

  • Try fixing CI / Python 3.11 test failures first.
  • Most pre-commit.ci - pr failures can be automagically fixed by commenting pre-commit.ci autofix below, followed by a git pull to bring the changes back to your computer.
  • If pre-commit.ci - pr says that a function is too long or complex, try breaking up that function into multiple short functions that each do one thing. See also these tips on writing clean scientific software.
  • If the CI / Documentation check ends with a cryptic error message, check out our documentation troubleshooting guide.
  • For a documentation preview, click on Details next to docs/readthedocs.org:plasmapy.

If this PR is marked as ready for review, someone should stop by to provide a code review and offer suggestions soon. ✅ If you don't get a review within a few days, please feel free to send us a reminder.

Please also use SI units within PlasmaPy, except when there is strong justification otherwise or in some examples.

We thank you once again!

@github-actions github-actions bot added the plasmapy.plasma Related to the plasmapy.plasma subpackage label Nov 14, 2023
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ee973c8) 96.91% compared to head (4733c46) 96.91%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2402   +/-   ##
=======================================
  Coverage   96.91%   96.91%           
=======================================
  Files         104      104           
  Lines        9118     9118           
=======================================
  Hits         8837     8837           
  Misses        281      281           

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

Signed-off-by: fazledyn-or <ataf@openrefactory.com>
Signed-off-by: fazledyn-or <ataf@openrefactory.com>
@github-actions github-actions bot added bug Issues describing unexpected behavior or defects. Remember: a bug is a sign of a missing test! packaging Related to packaging or distribution labels Nov 14, 2023
Signed-off-by: fazledyn-or <ataf@openrefactory.com>
Copy link
Member

@namurphy namurphy left a comment

Choose a reason for hiding this comment

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

Thank you for making this fix! I had been meaning to look into this further after we added the # noqa comments, but haven't had a chance. Great catch!

@namurphy namurphy merged commit b1f6838 into PlasmaPy:main Nov 15, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing unexpected behavior or defects. Remember: a bug is a sign of a missing test! packaging Related to packaging or distribution plasmapy.plasma Related to the plasmapy.plasma subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants