-
-
Notifications
You must be signed in to change notification settings - Fork 371
Description
I stumbled across office365/onedrive/filestorage/container_collection.py (line 16; commit ce11b31) and found that the container_type_id kwarg defaults to a random UUID, but this is done in the function definition, meaning "the expression is evaluated once".
https://docs.python.org/3/reference/compound_stmts.html#function-definitions
Default parameter values are evaluated from left to right when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that the same “pre-computed” value is used for each call.
I was wondering if this is the desired functionality, or if this might be a bug.
If it is a bug, a potential fix would be to default the parameter to None and then assign a generated UUID inside the body of the function.
def add(self, display_name, container_type_id=None):
if container_type_id is None:
container_type_id = uuid.uuid4()