Skip to content

Do not use mutable default arguments #800

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

Conversation

marlamb
Copy link

@marlamb marlamb commented Jul 9, 2024

Using mutable default arguments is a common Python problem, see e.g. https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

In this specific case the default argument even tries to setup some infrastructure settings at import time, which can potentially fail.

Note that this commit is changing the behavior for user passing in None to the changed method, as it will now create an AsyncClient with the options specified within the module. In the previous behavior it would have raised an exception deeper down the call stack (see http://github.com/microsoft/kiota-http-python/pull/383/files).

Using mutable default arguments is a common Python problem, see e.g.
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

In this specific case the default argument even tries to setup some
infrastructure settings at import time, which can potentially fail.

Note that this commit is changing the behavior for user passing in
`None` to the changed method, as it will now create an `AsyncClient`
with the options specified within the module. In the previous behavior
it would have raised an exception deeper down the call stack (see
http://github.com/microsoft/kiota-http-python/pull/383/files).
@marlamb marlamb requested a review from a team as a code owner July 9, 2024 13:02
@marlamb
Copy link
Author

marlamb commented Jul 9, 2024

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@baywet baywet enabled auto-merge (squash) July 9, 2024 15:06
@baywet
Copy link
Member

baywet commented Jul 9, 2024

@marlamb can you also replicate the change to https://github.com/microsoftgraph/msgraph-beta-sdk-python please?

@baywet baywet merged commit 4912f5a into microsoftgraph:main Jul 9, 2024
7 checks passed
@baywet
Copy link
Member

baywet commented Jul 9, 2024

@marlamb
Copy link
Author

marlamb commented Jul 9, 2024

@marlamb can you also replicate the change to https://github.com/microsoftgraph/msgraph-beta-sdk-python please?

@baywet I would, but you were faster 😄 .

Out of curiosity: what is the reason why it triggered releases on all repositories except for msgraph-sdk-python-core?

@baywet
Copy link
Member

baywet commented Jul 9, 2024

For core I found a defect in the release please configuration microsoftgraph/msgraph-sdk-python-core#628

For V1 and beta I ran into a defect with dependencies configuration which prevents the release.

All those caused by recent changes in the automation.

@marlamb
Copy link
Author

marlamb commented Jul 11, 2024

For core I found a defect in the release please configuration microsoftgraph/msgraph-sdk-python-core#628

For V1 and beta I ran into a defect with dependencies configuration which prevents the release.

All those caused by recent changes in the automation.

Thanks for the explanation, crossing fingers that you can fix the defects and looking forward to the releases!

@baywet
Copy link
Member

baywet commented Jul 11, 2024

yes, service libraries were just released yesterday and today

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