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 TypeError from being raised during creation of RuntimeError #12

Merged
merged 1 commit into from
Jan 19, 2018
Merged

Fix TypeError from being raised during creation of RuntimeError #12

merged 1 commit into from
Jan 19, 2018

Conversation

delirious-lettuce
Copy link
Contributor

@delirious-lettuce delirious-lettuce commented Jan 19, 2018

I was taking a break from reading this awesome book (EPI in Python) and noticed something while looking through the Python test_framework code.

raise RuntimeError("Tuple parser: expected " + str(

>>> parsers = [1, 2, 3]
>>> data = [3, 4, 5, 6, 7]

# Issue
>>> raise RuntimeError("Tuple parser: expected " + str(len(parsers)) + " values, got " + len(data))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: must be str, not int

# Cause
>>> " values, got " + len(data)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: must be str, not int
>>> "" + 1
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: must be str, not int

# Solution
>>> raise RuntimeError("Tuple parser: expected {} values, got {}".format(len(parsers), len(data)))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
RuntimeError: Tuple parser: expected 3 values, got 5

@tsunghsienlee tsunghsienlee merged commit c476794 into adnanaziz:dev Jan 19, 2018
@tsunghsienlee tsunghsienlee deleted the fix_typeerror branch January 19, 2018 21:38
@tsunghsienlee
Copy link
Collaborator

@delirious-lettuce Do you know which file trigger this error?

@delirious-lettuce
Copy link
Contributor Author

@tsunghsienlee ,

It wasn't raised from me running any particular file, I was just reading through the source code and it was highlighted in PyCharm so I took a look.
tuple_parse

@tsunghsienlee
Copy link
Collaborator

@delirious-lettuce I see, and many thanks for this. It seems I shall use some lint tools to find those bugs. Feel free to report anything you find, and I think many future fellow readers would be benefited from this.

@delirious-lettuce
Copy link
Contributor Author

delirious-lettuce commented Jan 19, 2018

@tsunghsienlee ,

No problem at all! I will definitely report anything else I find.

I also wanted to say thanks to you and your co-authors. I just found this book from a comment on HackerNews and got it in the mail a few days ago. Having these problems/solutions written in modern Python (3.6!) is so helpful for me!

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