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

allow overriding the session object to pass customized ones #129

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Apr 7, 2023

No description provided.

@@ -72,7 +73,7 @@ def __init__(self, **kwargs):
self.apidoc_cache_dir = kwargs.get('apidoc_cache_dir', apidoc_cache_dir_default)
self.apidoc_cache_name = kwargs.get('apidoc_cache_name', self._find_cache_name())

self._session = requests.Session()
self._session = kwargs.get('session') or requests.Session()
Copy link
Member

Choose a reason for hiding this comment

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

Do you use or here to make it lazy? I think this would always instantiate a session, even if one was passed.

Suggested change
self._session = kwargs.get('session') or requests.Session()
self._session = kwargs.get('session', requests.Session())

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, mostly because I am lazy myself ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

But you're right, the one is lazy, the other is not:

>>> a ={'lol': 'what'}
>>> a.get('lol', whaaaa)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'whaaaa' is not defined
>>> a.get('lol') or whaaaa
'what'

@evgeni evgeni merged commit 9e2590b into master Apr 11, 2023
@evgeni evgeni deleted the custom-session branch April 11, 2023 11:47
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