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: Missing substring should raise ValueError not KeyError + try-except code cleanup #2691

Merged

Conversation

kchawla-pi
Copy link
Contributor

@kchawla-pi kchawla-pi commented Sep 3, 2018

Fix for issue #2690

@kchawla-pi kchawla-pi mentioned this pull request Sep 3, 2018
@codecov-io
Copy link

Codecov Report

Merging #2691 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2691      +/-   ##
=========================================
- Coverage   67.61%   67.6%   -0.01%     
=========================================
  Files         340     340              
  Lines       43143   43143              
  Branches     5349    5349              
=========================================
- Hits        29170   29168       -2     
+ Misses      13271   13265       -6     
- Partials      702     710       +8
Flag Coverage Δ
#smoketests 50.58% <0%> (ø) ⬆️
#unittests 65.1% <0%> (+0.01%) ⬆️
Impacted Files Coverage Δ
nipype/utils/spm_docs.py 70.37% <0%> (ø) ⬆️
nipype/utils/profiler.py 43.1% <0%> (-1.15%) ⬇️
nipype/interfaces/dynamic_slicer.py 17.47% <0%> (ø) ⬆️
nipype/interfaces/nipy/preprocess.py 45.79% <0%> (ø) ⬆️
nipype/interfaces/io.py 54.59% <0%> (ø) ⬆️
nipype/interfaces/freesurfer/preprocess.py 66.11% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37f3781...c0d7cad. Read the comment docs.

@djarecka djarecka self-requested a review September 3, 2018 16:37
@djarecka
Copy link
Collaborator

djarecka commented Sep 3, 2018

@kchawla-pi - thank you for the PR!

@@ -59,5 +59,5 @@ def _strip_header(doc):
except ValueError:
index = len(doc)
return doc[:index]
except KeyError as e:
except ValueError as e:
Copy link
Member

Choose a reason for hiding this comment

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

I think this whole block might be better rewritten as

    try:
        index = doc.index(hdr)
    except ValueError as e:
        raise_from(IOError('This docstring was not generated by Nipype!\n'), e)
    index += len(hdr)
    index += 1
    doc = doc[index:]
    try:
        index = doc.index(cruft)
    except ValueError:
        index = len(doc)
    return doc[:index]

This helps make clear where the exception is expected, and avoids catching unexpected exceptions.

@effigies effigies added this to the 1.1.3 milestone Sep 3, 2018
@effigies
Copy link
Member

Hi @kchawla-pi. Do you have a few minutes to finish this one off? I think we're almost ready to go.

We'll be releasing 1.1.3 next week, and this would be a great addition!

@kchawla-pi
Copy link
Contributor Author

Ok.

@kchawla-pi kchawla-pi changed the title Fixed: Missing substring should raise ValueError not KeyError Fixed: Missing substring should raise ValueError not KeyError + try-except code cleanup Sep 17, 2018
@kchawla-pi
Copy link
Contributor Author

Congrats on the upcoming release! :~)

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.

4 participants