Cursor raises unhelpful error when not given a function #452

Closed
opened 2017-09-06 15:43:11 -07:00 by clayadavis · 0 comments
clayadavis commented 2017-09-06 15:43:11 -07:00 (Migrated from github.com)

This is how the cursor method should be used, quoted from the docs:

    results = twitter.cursor(twitter.search, q='twitter')

If one is refactoring some existing code to use a cursor, it can be very easy to instead write the following:

    results = twitter.cursor(twitter.search(q='twitter'))

Providing the cursor method with the result from a Twython function call results in a very unhelpful error message:

File ".../twython/api.py", line 475, in cursor
method "%s"' % function.__name__)

AttributeError: 'dict' object has no attribute '__name__'

Obviously one can't check every possible input, but this mistake is very easy to make -- this issue comes from a labmate's experience. Luckily it is also very easy to fix. PR to follow.

This is how the cursor method should be used, quoted from the docs: ```python results = twitter.cursor(twitter.search, q='twitter') ``` If one is refactoring some existing code to use a cursor, it can be very easy to instead write the following: ```python results = twitter.cursor(twitter.search(q='twitter')) ``` Providing the cursor method with the result from a Twython function call results in a very unhelpful error message: File ".../twython/api.py", line 475, in cursor method "%s"' % function.__name__) AttributeError: 'dict' object has no attribute '__name__' Obviously one can't check every possible input, but this mistake is very easy to make -- this issue comes from a labmate's experience. Luckily it is also very easy to fix. PR to follow.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: repos/twython#452
No description provided.