-
Notifications
You must be signed in to change notification settings - Fork 36
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
Authorize qualifier dictionaries in Dependency #632
Authorize qualifier dictionaries in Dependency #632
Conversation
|
||
self.qualifier: str | None | ||
if isinstance(qualifier, dict): | ||
for q in set(qualifier.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to cast on set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast to set is way to copy it. Otherwise python complains because the size of the dictionary change during the iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it's ok. Using a set
or a list
seems to do the same.
>>> a = {1: "one", 2: "two", 3: "three"}
>>> for k in list(a.keys()):
... a[1 + len(a)] = "something"
... print(k)
...
1
2
3
>>> a
{1: 'one', 2: 'two', 3: 'three', 4: 'something', 5: 'something', 6: 'something'}
>>> for k in a:
... a[1 + len(a)] = "something"
... print(k)
...
1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
>>>
self.qualifier: str | None | ||
if isinstance(qualifier, dict): | ||
for q in set(qualifier.keys()): | ||
v = qualifier[q] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for q, v in qualifier.items()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot do that because I am changing the size of the dictionary in the loop (poping an element) and python doesn't like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok with a set
:
>>> a = {1: "one", 2: "two", 3: "three"}
>>> for k in set(a.keys()):
... a[1 + len(a)] = "something"
... print(k)
...
1
2
3
>>> for k in a:
... a[1 + len(a)] = "something"
... print(k)
...
1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
>>>
f7c506d
to
aa496ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as Nico does not have any other comment, and that your answers are right, I think we can approve the MR.
Accept a qualifier dictionary in Dependency. This dictionary can be formatted the old fashion (some qualifier are not present) or following the "args" schemes (the falg qualifier value is True or False).
It will require a corresponding patch in the specs to update the wrappers of Dependency.