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

Fix some type errors #948

Closed
wants to merge 1 commit into from
Closed

Conversation

xxc3nsoredxx
Copy link
Contributor

@xxc3nsoredxx xxc3nsoredxx commented Nov 27, 2022

Knock out some low-hanging fruit given by running

mypy --pretty --show-error-context .

inside lib/ (191 total errors found).

portage/package/ebuild/_config/special_env_vars.py:248: error: Incompatible types in assignment (expression has type "FrozenSet[str]", variable has type "List[str]")  [assignment]
    environ_whitelist = frozenset(environ_whitelist)
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
portage/package/ebuild/_config/special_env_vars.py:353: error: Incompatible types in assignment (expression has type "FrozenSet[str]", variable has type "List[str]")  [assignment]
    environ_filter = frozenset(environ_filter)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
portage/__init__.py: note: At top level:
portage/__init__.py:537: error: Need type annotation for "_testing_eapis" [var-annotated]
    _testing_eapis = frozenset([])
                     ^~~~~~~~~~~~~
portage/checksum.py:342: error: Incompatible types in assignment (expression has type "int", variable has type "bool")  [assignment]
            prelink_capable = 1
                              ^
portage/process.py:64: error: Incompatible types in assignment (expression has type "None", variable has type "str")  [assignment]
            _fd_dir = None
                      ^~~~
portage/process.py:68: error: Incompatible types in assignment (expression has type "None", variable has type "str")  [assignment]
        _fd_dir = None
                  ^~~~
_emerge/Package.py: note: At top level:
_emerge/Package.py:865: error: Incompatible types in assignment (expression has type "FrozenSet[str]", variable has type "Set[str]")  [assignment]
    _all_metadata_keys = frozenset(_all_metadata_keys)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
portage/getbinpkg.py:46: error: Incompatible types in assignment (expression has type "Tuple[Type[Exception], ...]", variable has type "List[Type[Exception]]")  [assignment]
    _all_errors = tuple(_all_errors)
                  ^~~~~~~~~~~~~~~~~~

Signed-off-by: Oskari Pirhonen xxc3ncoredxx@gmail.com

@xxc3nsoredxx
Copy link
Contributor Author

Setting in lib/portage/__init__.py

_testing_eapis = frozenset([""])

was incorrect since that would result in eapi_is_supported() returning True for empty string. Reverted.

lib/_emerge/Package.py Outdated Show resolved Hide resolved
lib/portage/package/ebuild/_config/special_env_vars.py Outdated Show resolved Hide resolved
lib/portage/process.py Outdated Show resolved Hide resolved
_all_metadata_keys = set(x for x in portage.auxdbkeys)
_all_metadata_keys.update(Package.metadata_keys)
_all_metadata_keys = frozenset(_all_metadata_keys)
_all_metadata_keys = frozenset(set(portage.auxdbkeys).union(Package.metadata_keys))
Copy link
Contributor

Choose a reason for hiding this comment

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

This certainly looks nicer.

I'm a bit suspicious of this expression in the original code: x for x in portage.auxdbkeys. If auxdbkeys is already a collection, I wonder why we piled a generator on top.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to come from when elements of auxdbkeys were conditionally included, up until 1dbe0f2

--- a/lib/_emerge/Package.py
+++ b/lib/_emerge/Package.py
@@ -791,8 +791,7 @@ def with_use(self, use):
 			pkg = self
 		return pkg
 
-_all_metadata_keys = set(x for x in portage.auxdbkeys \
-	if not x.startswith("UNUSED_"))
+_all_metadata_keys = set(x for x in portage.auxdbkeys)
 _all_metadata_keys.update(Package.metadata_keys)
 _all_metadata_keys = frozenset(_all_metadata_keys)

Some of the x for x did get dropped, so it was probably oversight.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that explanation makes me feel better. Thanks!

Knock out some low-hanging fruit given by running

    mypy --pretty --show-error-context .

inside lib/ (191 total errors found).

portage/package/ebuild/_config/special_env_vars.py:248: error: Incompatible
types in assignment (expression has type "FrozenSet[str]", variable has type
"List[str]")  [assignment]
    environ_whitelist = frozenset(environ_whitelist)
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
portage/package/ebuild/_config/special_env_vars.py:353: error: Incompatible
types in assignment (expression has type "FrozenSet[str]", variable has type
"List[str]")  [assignment]
    environ_filter = frozenset(environ_filter)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
portage/checksum.py:342: error: Incompatible types in assignment (expression
has type "int", variable has type "bool")  [assignment]
            prelink_capable = 1
                              ^
_emerge/Package.py: note: At top level:
_emerge/Package.py:865: error: Incompatible types in assignment (expression has
type "FrozenSet[str]", variable has type "Set[str]")  [assignment]
    _all_metadata_keys = frozenset(_all_metadata_keys)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
portage/getbinpkg.py:46: error: Incompatible types in assignment (expression
has type "Tuple[Type[Exception], ...]", variable has type
"List[Type[Exception]]")  [assignment]
    _all_errors = tuple(_all_errors)
                  ^~~~~~~~~~~~~~~~~~

Signed-off-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants