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

Underlying dependency yarl not accepting NoneType parameter values? #1944

Closed
mijolabs opened this issue Aug 19, 2022 · 1 comment
Closed
Labels
Bug This is regarding a bug with the library

Comments

@mijolabs
Copy link

AsyncClient.search_recent_tweets() (and probably Tweepy's other methods using yarl) does not accept NoneType values for certain parameters, despite Tweepy documentation listing them as an acceptable.

I have a class method calling search_recent_tweets with since_id and next_token parameter values set to None by default.

async def search_recent(
    self,
    search_query: str,
    since_id: str = None,
    next_token: str = None,
    ) -> dict:

The method later calls search_recent_tweets() with the provided parameters, like

return await self.search_recent_tweets(search_query, since_id=since_id, next_token=next_token, ...)

Which results in yarl throwing a TypeError (unless a valid value has been provided to since_id and next_token).

r = await twitter.search_recent("tweepy")


Traceback (most recent call last):
...
File ".../lib/python3.9/site-packages/yarl/_url.py", line 916, in _query_var
    raise TypeError(
TypeError: Invalid variable type: value should be str, int or float, got None of type <class 'NoneType'>
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x104992880>

Could this have something to do with yarl not supporting boolean values, and that includes NoneTypes too?

My current workaround is to create a dict inside the method with the func params and only add since_id/next_token if they're not None, then pass the **params to search_recent_tweets() that way. It's not pretty, but works.

@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label Aug 20, 2022
@Harmon758
Copy link
Member

Thanks for the bug report! This should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library
Projects
None yet
Development

No branches or pull requests

2 participants