Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 910171 - depgraph.py: incorrect type annotations for myopts
Summary: depgraph.py: incorrect type annotations for myopts
Status: UNCONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-09 22:16 UTC by Oskari Pirhonen
Modified: 2023-07-11 05:02 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oskari Pirhonen 2023-07-09 22:16:05 UTC
When investigating bug 909853 I found what looks to me like incorrect type annotations for the myopts arg:

- def backtrack_depgraph() on line 11409 [1] annotates it as Dict[str, Any]
- def _backtrack_depgraph() on line 11431 [2] annotates it as Dict[str, Any]
- def resume_depgraph() on line 11535 [3] annotates it as Dict[str, str]
- def _resume_depgraph() on line 11553 [4] annotates it as Dict[str, str]

Copying just the debug output added into _show_unsatisfied_dep() from my comment in the other bug you can see that the values in the dict can be (at least) of type bool, int, string:

self._frozen_config.myopts = {'--ask-enter-invalid': True, '--pretend': True, '--jobs': 16, '--regex-search-auto': 'y', '--verbose': True}
self._frozen_config.myopts.get("--usepkgonly", "y") = 'y'

Annotating as Dict[str, Any] is technically correct but vague. Whereas Dict[str, str] is incorrect based on the output above. Assuming resume_depgraph() does not use its own format for myopts, that is.

The annotations were introduced in 7e8a730b [5].

Also CC'ing Ninpo in case they're interested in this as mentioned by Sam in the other bug.

1: https://gitweb.gentoo.org/proj/portage.git/tree/lib/_emerge/depgraph.py?id=b199d0307b47f9fb06dbe533d7e24926a561c238#n11409
2: https://gitweb.gentoo.org/proj/portage.git/tree/lib/_emerge/depgraph.py?id=b199d0307b47f9fb06dbe533d7e24926a561c238#n11431
3: https://gitweb.gentoo.org/proj/portage.git/tree/lib/_emerge/depgraph.py?id=b199d0307b47f9fb06dbe533d7e24926a561c238#n11535
4: https://gitweb.gentoo.org/proj/portage.git/tree/lib/_emerge/depgraph.py?id=b199d0307b47f9fb06dbe533d7e24926a561c238#n11553
5: https://gitweb.gentoo.org/proj/portage.git/commit/lib/_emerge/depgraph.py?id=7e8a730b85b77f9495f4999ac173dc726777203f
Comment 1 Ninpo 2023-07-09 23:33:44 UTC
Definitely interested and I can see how these difficulties easily enter into things from what I've gleaned thus far going through opts input and parsing.
Comment 2 Larry the Git Cow gentoo-dev 2023-07-11 05:02:01 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=f228252f4b4c3b33ff1e199f55bec9a6a104b80c

commit f228252f4b4c3b33ff1e199f55bec9a6a104b80c
Author:     Berin Aniesh <berinaniesh@gmail.com>
AuthorDate: 2023-07-10 03:10:07 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-07-11 05:00:43 +0000

    depgraph.py: fix wrong type annotations
    
    Fixes: 7e8a730b85b77f9495f4999ac173dc726777203f
    Bug: https://bugs.gentoo.org/910171
    Signed-off-by: Berin Aniesh <berinaniesh@gmail.com>
    Closes: https://github.com/gentoo/portage/pull/1067
    Signed-off-by: Sam James <sam@gentoo.org>

 lib/_emerge/depgraph.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)