Closed behrmann closed 4 years ago
@keszybz you are our python guru on call, any idea? ;-)
I've finally had some time to follow the logic around a bit and this a bit of a limitation in mypy. mypy cannot deduce, that loopdev
can only be None
, when args.esp_partno
and args.xbootldr_partno
are also None
, since loopdev
will be None
, if the image is not a disk image, but then determine_partition_table
forces them to be None
as well. At least if I understand the situation correctly.
The simplest solution would be to add and loopdev is not None
to both lines in mount_image
. I'll prepare a patch once I'm in a less crappy wifi.
I've just opened #374 with the most straight-forward solution. I hope the reasoning is correct.
I've also rechecked mkosi with mypy --strict
, which on my mypy 0.730 sets --warn-unused-configs
, --disallow-subclassing-any
, --disallow-any-generics
, --disallow-untyped-calls
, --disallow-untyped-defs
, --disallow-incomplete-defs
, --check-untyped-defs
, --disallow-untyped-decorators
, --no-implicit-optional
, --warn-redundant-casts
, --warn-unused-ignores
, --warn-return-any
, --no-implicit-reexport
, to get a few more errors
mkosi:69: error: Missing type parameters for generic type "CompletedProcess"
mkosi:107: error: Function is missing a return type annotation
mkosi:111: error: Function is missing a return type annotation
mkosi:412: error: unused 'type: ignore' comment
mkosi:432: error: Missing type parameters for generic type "Callable"
mkosi:443: error: Missing type parameters for generic type "TemporaryDirectory"
mkosi:1917: error: Missing type parameters for generic type "CompletedProcess"
mkosi:1926: error: Missing type parameters for generic type "CompletedProcess"
mkosi:3127: error: Missing type parameters for generic type "TemporaryDirectory"
mkosi:3128: error: Missing type parameters for generic type "TemporaryDirectory"
mkosi:3201: error: Function is missing a type annotation
mkosi:3206: error: Function is missing a type annotation
mkosi:3257: error: Function is missing a type annotation
mkosi:3263: error: Name '__class__' is not defined
mkosi:3266: error: Function is missing a type annotation
mkosi:3282: error: Function is missing a type annotation
mkosi:3286: error: Function is missing a type annotation
mkosi:3288: error: Name '__class__' is not defined
mkosi:3290: error: Call to untyped function "camel_to_arg" in typed context
mkosi:3307: error: Call to untyped function "ini_key_to_cli_arg" in typed context
mkosi:3331: error: Call to untyped function "ArgumentParserMkosi" in typed context
mkosi:3408: error: Call to untyped function "doc" of "SourceFileTransfer" in typed context
mkosi:3457: error: Returning Any from function declared to return "ArgumentParserMkosi"
mkosi:3464: error: Function is missing a type annotation for one or more arguments
mkosi:3557: error: Redundant cast to "CommandLineArguments"
mkosi:3561: error: Function is missing a type annotation for one or more arguments
mkosi:3580: error: Redundant cast to "CommandLineArguments"
mkosi:3607: error: Returning Any from function declared to return "Optional[int]"
mkosi:4344: error: Missing type parameters for generic type "TemporaryDirectory"
mkosi:4726: error: Function is missing a type annotation
mkosi:4772: error: Call to untyped function "run_verb" in typed context
Found 31 errors in 1 file (checked 1 source file)
These are addressed in #375.
When they get merged I'd like to add mypy
to the tests that are being run. --strict
is quite a bit too harsh, but I guess a subset of its options might be helpful. I also need to see whether the current mypy 0.750 introduced anything new. Once this is done I will finally test, whether mypyc could compile this, hopefully in a standalone binary.
I've reworked the PR on this into #389, which makes mkosi mypy strict compliant (with mypy 0.750, 0.740 for example would throw an error because of a regression mypy, that has since been fixed) and adds mypy to the tests that get run by semaphore.
I've now gone through all options that mypy has, which was a nice learning experience and decided to add all current strict switches to the mypy section of setup.cfg.
There is one last switch I'd like to switch on unreachable code, that I'd like to switch one, but currently it is triggered and I'm not quite sure if it's a false positve, because that PR also introduced some indentation with tabs. I asked about it in #357 in the hope to reach the original author.
Running a current mypy on mkosi gives the following warnings
The last line is harmless and addressed in #368. I guess it simply prevents the
--directory
switch to take effect.I haven't yet followed through the first error, though. The
partition
function cannot deal with theNone
thatmount_image
saysloopdev
might be. The only user ofmount_image
is inbuild_image
which gets theloopdev
it passes on fromattach_image_loopback
, which will produce aNone
ifraw
isNone
. That seems to be the case if the output format is not a disk format. Right now I wonder where to best untangle this. Any ideas?