Skip to content

Fully type check the gnome module#9704

Merged
eli-schwartz merged 17 commits intomesonbuild:masterfrom
dcbaker:submit/fully-type-check-the-gnome-module
Jan 19, 2022
Merged

Fully type check the gnome module#9704
eli-schwartz merged 17 commits intomesonbuild:masterfrom
dcbaker:submit/fully-type-check-the-gnome-module

Conversation

@dcbaker
Copy link
Member

@dcbaker dcbaker commented Dec 7, 2021

Finally, with these changes (and the ones in #9700), the gnome module has become type safe, and with it all callers of CustomTarget, so I can finally get to the work I actually wanted to, fixing the layering violation between the build and interpreter modules!

@lgtm-com
Copy link

lgtm-com bot commented Dec 7, 2021

This pull request introduces 3 alerts when merging d459623 into 824e091 - view on LGTM.com

new alerts:

  • 2 for Unused local variable
  • 1 for Variable defined multiple times

@codecov
Copy link

codecov bot commented Dec 7, 2021

Codecov Report

Merging #9704 (b8670e7) into master (4b9ec4f) will decrease coverage by 3.36%.
The diff coverage is n/a.

❗ Current head b8670e7 differs from pull request most recent head 26e87bc. Consider uploading reports for the commit 26e87bc to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9704      +/-   ##
==========================================
- Coverage   67.75%   64.38%   -3.37%     
==========================================
  Files         400      200     -200     
  Lines       85560    42701   -42859     
  Branches    18865     9321    -9544     
==========================================
- Hits        57967    27491   -30476     
+ Misses      23053    13005   -10048     
+ Partials     4540     2205    -2335     
Impacted Files Coverage Δ
compilers/cython.py 43.18% <0.00%> (-38.64%) ⬇️
backend/ninjabackend.py 71.19% <0.00%> (-2.07%) ⬇️
scripts/gtkdochelper.py 67.83% <0.00%> (-1.76%) ⬇️
envconfig.py 73.20% <0.00%> (-1.68%) ⬇️
build.py 73.99% <0.00%> (-0.58%) ⬇️
wrap/wrap.py 61.67% <0.00%> (-0.58%) ⬇️
compilers/compilers.py 80.55% <0.00%> (-0.47%) ⬇️
msubprojects.py 28.88% <0.00%> (-0.43%) ⬇️
backend/backends.py 82.54% <0.00%> (-0.21%) ⬇️
minstall.py 66.24% <0.00%> (-0.19%) ⬇️
... and 213 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b9ec4f...26e87bc. Read the comment docs.

@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch from d459623 to cca60f6 Compare December 8, 2021 18:12
@lgtm-com
Copy link

lgtm-com bot commented Dec 8, 2021

This pull request introduces 3 alerts when merging cca60f6 into 1e5d7f2 - view on LGTM.com

new alerts:

  • 2 for Unused local variable
  • 1 for Variable defined multiple times

@dcbaker dcbaker added the typing label Dec 9, 2021
@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch from cca60f6 to 533da2f Compare January 6, 2022 22:55
@lgtm-com
Copy link

lgtm-com bot commented Jan 6, 2022

This pull request introduces 3 alerts when merging 533da2f into 484a389 - view on LGTM.com

new alerts:

  • 2 for Unused local variable
  • 1 for Variable defined multiple times

@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch from 533da2f to 2268289 Compare January 10, 2022 17:44
@lgtm-com
Copy link

lgtm-com bot commented Jan 10, 2022

This pull request introduces 1 alert when merging 2268289 into 251d6f0 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch 2 times, most recently from 3947e87 to aed1a72 Compare January 10, 2022 21:04
@nirbheek
Copy link
Member

Let's merge this immediately after 0.61.1?

RunTargets and AliasTargets may depend on RunTargets, so annotate them
that way. The Gnome module relies on this internally.
…ncludes_and_update_depends

There is the problem of the annotations themselves, then there is
the problem with depends being mutated. The mutation side effect is a
problem in itself, but there's also the problem that we really want to
use Sequence, which isn't mutable.
@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch from aed1a72 to 9f0035c Compare January 18, 2022 19:04
This is hard to fix, and it's really doing something bad anyway. But we
know it's right, so just tell mypy to not worry about it.
gnome points out that CustomTargets can be linked with, so we should
allow that.
This is better as it avoids building unnecessary lists, and two fixes
the typing issue from concatenating lists of different types.
Which is pretty much necessary to make anything involving unions of
lists work
These don't return `Target`, they return `BuildTarget | CustomTarget |
CustomTargetIndex`
_get_gir_target_deps

The typing issues with these are tightly intertwined, so it didn't
really make sense to solve them independently
Which is one incorrect type annotation, and a couple of instances of
concatenating lists of unlike types. List being invariant is super
annoying.
Since they don't use the instance or class state, they should be static
methods.
@dcbaker dcbaker force-pushed the submit/fully-type-check-the-gnome-module branch from 9f0035c to 26e87bc Compare January 18, 2022 21:13
builddir = os.path.join(state.environment.get_build_dir(), state.subdir)

depends: T.List[T.Union['FileOrString', build.GeneratedTypes, build.Executable, build.SharedLibrary, build.StaticLibrary]] = []
depends: T.List[T.Union['FileOrString', 'build.GeneratedTypes', build.BuildTarget]] = []
Copy link
Member

Choose a reason for hiding this comment

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

How did this ever work? Weird. build.GeneratedTypes is a typechecking-only variable but it never produced undefined variable errors when running live?

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the answer to this is: https://www.python.org/dev/peps/pep-0526/#runtime-effects-of-type-annotations

A variable inside a function doesn't get stored in __annotations__ of the function, unlike class or module variables, and in fact isn't even evaluated...

@eli-schwartz eli-schwartz merged commit acef5a9 into mesonbuild:master Jan 19, 2022
@dcbaker dcbaker deleted the submit/fully-type-check-the-gnome-module branch January 19, 2022 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants