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

Authorize qualifier dictionaries in Dependency #632

Conversation

JulienBortolussiAda
Copy link
Contributor

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.


self.qualifier: str | None
if isinstance(qualifier, dict):
for q in set(qualifier.keys()):
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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]
Copy link
Contributor

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()

Copy link
Contributor Author

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.

Copy link
Contributor

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
>>> 

src/e3/anod/deps.py Show resolved Hide resolved
@JulienBortolussiAda JulienBortolussiAda force-pushed the dependency_add_dict_qualifier branch from f7c506d to aa496ad Compare October 3, 2023 12:47
@JulienBortolussiAda JulienBortolussiAda marked this pull request as ready for review October 4, 2023 12:03
Copy link
Contributor

@grouigrokon grouigrokon left a 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.

@JulienBortolussiAda JulienBortolussiAda merged commit 8527452 into AdaCore:master Oct 12, 2023
6 checks passed
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.

3 participants