Skip to content

CLN: fix python26 invalid exception #4000

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

Merged
merged 1 commit into from
Jun 23, 2013
Merged

CLN: fix python26 invalid exception #4000

merged 1 commit into from
Jun 23, 2013

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Jun 23, 2013

No description provided.

@cpcloud
Copy link
Member Author

cpcloud commented Jun 23, 2013

found this using my exception finding tool :) there's now a --validate option that let's you check for invalid format strings. invalid meaning those strings that have an unequal number of unique format string args to str.format args

@jtratner
Copy link
Contributor

👍

@ghost ghost assigned cpcloud Jun 23, 2013
@cpcloud
Copy link
Member Author

cpcloud commented Jun 23, 2013

i'm going to convert many of these to IOError

@jtratner
Copy link
Contributor

That makes sense...it's slightly hard to test for these because of the intricacies with network errors. I somewhat wish we could run these functions on pre-existing data (i.e., download them once and not need network connection for all tests), maybe have one test (potentially) that checks for elegant network handling and then that would be it. (maybe mock out the urllib library?)

@cpcloud
Copy link
Member Author

cpcloud commented Jun 23, 2013

probably also good to get rid of idioms like this

try:
    gnarly_function
except ValueError:
    raise

any reason to keep those? will just bubble up anyway...unless i'm missing something about exception semantics

@jtratner
Copy link
Contributor

yes, that's silly...unless there's a second except statement later, then
it matters...i.e.

try:

some func

except ValueError:
raise
except Exception as e:
handle_other_exception(e)

On Sat, Jun 22, 2013 at 9:19 PM, Phillip Cloud [email protected]:

probably also good to get rid of idioms like this

try:
gnarly_functionexcept ValueError:
raise

any reason to keep those? will just bubble up anyway...unless i'm missing
something about exception semantics


Reply to this email directly or view it on GitHubhttps://github.com//pull/4000#issuecomment-19867495
.

@cpcloud
Copy link
Member Author

cpcloud commented Jun 23, 2013

yep that would be why it's hard to spot those in my exception-finding script in a general way otherwise i would do it...i suppose you could say "if reraise is in an exception block and there are no other blocks then mark as invalid". i will see how difficult that is

@jtratner
Copy link
Contributor

Depending on how you're parsing the python, you can notice the except clause can only follow a try clause, and the next time something is at same level, then you're our of try clause.

@cpcloud
Copy link
Member Author

cpcloud commented Jun 23, 2013

i'll probably do this:

In [4]: ast.parse('try:\n    print "sdf"\nexcept ValueError:\n    print "yo momma"\nexcept Exception:\n    raise')
Out[4]: <_ast.Module at 0x679f450>

In [5]: mod = ast.parse('try:\n    print "sdf"\nexcept ValueError:\n    print "yo momma"\nexcept Exception:\n    raise')

In [6]: mod.body
Out[6]: [<_ast.TryExcept at 0x679f810>]

In [7]: mod.body[0]
Out[7]: <_ast.TryExcept at 0x679f810>

In [8]: t = mod.body[0]

In [9]: t
Out[9]: <_ast.TryExcept at 0x679f810>

In [10]: t.
t._attributes       t.col_offset        t.__doc__           t.__getattribute__  t.__init__          t.__new__           t.__reduce_ex__     t.__sizeof__        t.__weakref__
t.body              t.__delattr__       t._fields           t.handlers          t.lineno            t.orelse            t.__repr__          t.__str__
t.__class__         t.__dict__          t.__format__        t.__hash__          t.__module__        t.__reduce__        t.__setattr__       t.__subclasshook__

In [10]: t.body
Out[10]: [<_ast.Print at 0x679f850>]

In [11]: t.handlers
Out[11]: [<_ast.ExceptHandler at 0x679f890>, <_ast.ExceptHandler at 0x679fa10>]

and use len(t.handlers) to detect it

@cpcloud cpcloud closed this Jun 23, 2013
@cpcloud cpcloud reopened this Jun 23, 2013
cpcloud added a commit that referenced this pull request Jun 23, 2013
@cpcloud cpcloud merged commit 01a8648 into pandas-dev:master Jun 23, 2013
@cpcloud cpcloud deleted the fix-invalid-exception-spec branch June 23, 2013 05:25
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