Commit Graph

131 Commits

Author SHA1 Message Date
hauntsaninja 95895492f5 Make run_mypy.py work in mypy_primer
See also https://github.com/hauntsaninja/mypy_primer/pull/77
2025-04-18 19:52:05 -04:00
Dylan Baker 1f4bb37372 modules/cmake: Make fully type safe
Mostly this was just adding a few asserts for options, and one bug fix
from the option refactor
2025-04-02 12:40:51 -04:00
Dylan Baker f0795e14c5 environment: make fully type safe
This as much as anything is to stop lying to envconfig about the
potential types it will be given.
2025-03-01 13:30:06 +02:00
Dylan Baker 177148686c options: split UserIntegerOption and UserUmaskOption
They are very similar, but they are not exactly the same. By splitting
them we can get full type safety, and run mypy over the options.py file!
2025-02-05 17:45:38 +02:00
Eli Schwartz d353219e17
run_mypy: register utils/vsenv.py, as it is type-safe 2024-09-06 15:29:30 -04:00
Dylan Baker ca5490f021 machinefile: Make fully typesafe
With the use of `typing_extensions.TypeAlias` we can get recursive
types, which solves most of the issues we had with this file.
2024-09-06 11:41:06 -07:00
Dylan Baker 978a58ea1e unittests: Add type annotations to the helpers module 2024-07-16 15:13:31 -07:00
Dylan Baker d617dc6869 modules: rename qt.py -> _qt.py
Since it's an implementation detail, and shouldn't be exposed. This also
helps give better error messages when a user writes `import('qt')`,
since otherwise you get an error about `qt doesn't have an initialize
method`, and now you get `qt module doesn't exist`.
2024-04-09 12:27:39 -07:00
Charles Brunet 2b37101998 meson format command 2024-04-08 10:43:57 -07:00
Eli Schwartz 65ee397f34
cuda module: fully type annotate
Special notes:
- _nvcc_arch_flags is always called with exact arguments, no need for
  default values
- min_driver_version has its args annotation loosened because it has to
  fit the constraints of the module interface?
2024-02-12 23:51:35 -05:00
Dylan Baker 7d0d610045 ast/introspection: make mypy clean 2024-01-08 19:33:05 -05:00
Dylan Baker 25fa0e9721 ast: mark visitor and preprocessor as mypy safe
They already are warning free
2024-01-08 19:33:05 -05:00
Dylan Baker 5cd1147354 ast/printer: fix mypy issues
Other than one case that I think cannot be actually hit (or it would
fail).
2024-01-08 19:33:05 -05:00
Eli Schwartz 78e23e48f2 backends: correct nonebackend return annotation and check in run_mypy
The only backend that can return values in generate() is ninja, so this
was useless cruft.
2023-12-11 21:13:20 +02:00
Eli Schwartz cf64e062bb run_mypy: avoid type-checking tools against every possible python version 2023-11-26 17:12:52 -05:00
Tristan Partin 8490eaa29d Add simd.py to run_mypy.py 2023-10-09 17:25:05 -04:00
Eli Schwartz 1ed619d196
run_mypy: add option to run once for each supported version of python
This allows verifying that meson is type-safe under older versions of
Python, which it currently is. Different versions of Python sometimes
have different supported types for an API.

Verify this in CI.

(We flush output to ensure CI prints lines in the right order.)
2023-08-18 15:38:13 -04:00
Dylan Baker 9ae6e38e90 mypy: add templates to checked modules 2023-07-25 15:50:21 -04:00
Eli Schwartz a53c6687b6
fully type mconf.py 2023-06-25 10:08:15 -04:00
Eli Schwartz b411be5edc
fully type mdist.py 2023-06-25 10:08:15 -04:00
Dylan Baker b01ae087f5 cargo: Add a builder module to the cargo package
This is a helper, currently only used by cargo. It could be moved later
if there are other users.
2023-06-07 19:20:30 -07:00
Eli Schwartz 2d26c272c3
run_mypy: accept the path to an alternative mypy executable
mypy might be installed with a different python than the one run_mypy.py
is using.
2023-03-02 15:52:45 -05:00
Eli Schwartz 3946f1eb17
Revert "target python 3.10 as the mypy language version"
This reverts commit 0b7d935a84.

The issue is fixed in mypy 1.0.0 now.
2023-03-02 15:51:27 -05:00
Eli Schwartz 6c3b0973c4
run_mypy: passthrough unknown options to mypy itself
Useful for running as a thin wrapper in other contexts that expect the
ability to run mypy itself with arbitrary arguments.
2023-03-02 15:33:19 -05:00
Eli Schwartz 2d0c9ce5f2
properly type utils/core.py and add it to mypy
EnvironmentVariables was always broken, it used MutableMapping because
everyone <3 abstract interfaces, especially when they are broken and
don't actually do what you want.

This needs a dict interface, exposing `.copy()`. We either use a dict or
os._Environ, and the latter also supports that.

Also fix a broken import, and the fallout from forgetting to update the
signature of self.envvars in commit b926374205.
2023-01-16 15:30:12 -05:00
Dylan Baker 6ed6c8cdba modules: fully type the Qt* modules
The base module is fully typed, but the numbered version are not, though
it's pretty trivial to do so.
2023-01-10 09:53:22 -08:00
Dylan Baker e8a88f5320 modules: add type annotations to the `__init__` module 2023-01-10 09:53:22 -08:00
Eli Schwartz 0b7d935a84
target python 3.10 as the mypy language version
mypy has a bug when running on/for 3.11 which results in incorrect
analysis of the codebase, specifically due to enum.Enum's self.name

See:

https://github.com/python/typeshed/issues/7564
https://github.com/python/mypy/issues/12483
2022-11-06 12:20:36 -05:00
Eli Schwartz 4e374d5cef
run_mypy: add extra logging and permit specifying files to check
If those files are not yet known to be typed, skip them. This makes it
possible to trivially check a shortlist of files that were just changed
and see if they regress our mypy coverage. Ideal for use in a git
pre-commit hook.
2022-10-24 00:37:51 -04:00
Xavier Claessens 2dfd952eb9 Move classes used by scripts to their own module
Those classes are used by wrapper scripts and we should not have to
import the rest of mesonlib, build.py, and all their dependencies for
that.

This renames mesonlib/ directory to utils/ and add a mesonlib.py module
that imports everything from utils/ to not have to change `import
mesonlib` everywhere. It allows to import utils.core without importing
the rest of mesonlib.
2022-09-28 19:36:13 -04:00
Dylan Baker 4135925b60 run_mypy: Add modules/pkgconfig to the list of checked modules 2022-08-18 21:57:36 -04:00
Dylan Baker a78992dd81 interpreter: move handling of module stability to interpreter
Thanks to `ModuleInfo`, all modules are just named `foo.py` instead of
`unstable_foo.py`, which simplifies the import method a bit. This also
allows for accurate FeatureNew/FeatureDeprecated use, as we know when
the module was added and if/when it was stabilized.
2022-08-17 16:25:36 -04:00
Dylan Baker 0bf66ff02c modules/wayland: Add full type checking 2022-07-17 12:58:17 -04:00
Dylan Baker 4acab57d47 modules/icestorm: use type checking 2022-05-23 23:32:47 -04:00
Dylan Baker 10fc19ecb4 modules: add typing to the modtest module 2022-05-23 23:32:47 -04:00
Eli Schwartz a6e08e8fa7
use a more sane check instead of run_custom_lint
Unfortunately, checking for strings without context is exceedingly prone
to false positives, while missing anything that indirectly opens a file.

Python 3.10 has a feature to warn about this though -- and it uses a
runtime check which runs at the same time that the code fails to open
files in the broken Windows locale. Set this up automatically when
running the testsuite.

Sadly, Python's builtin feature to change the warning level, e.g. by
setting EncodingWarning to error at startup, is utterly broken if you
want to limit it to only certain modules. This is tracked in order to be
more efficiently ignored at https://bugs.python.org/issue34624 and
https://github.com/python/cpython/pull/9358

It is also very trigger happy and passing stuff around via environment
variable either messes with the testsuite, or with thirdparty programs
which are implemented in python *such as lots of gnome*, or perhaps
both.

Instead, add runtime code to meson itself, to add a hidden "feature".
In the application source code, running the 'warnings' module, you can
actually get the expected behavior that $PYTHONWARNINGS doesn't have. So
check for a magic testsuite variable every time meson starts up, and if
it does, then go ahead and initialize a warnings filter that makes
EncodingWarning fatal, but *only* when triggered via Meson and not
arbitrary subprocess scripts.
2022-03-01 21:42:52 -05:00
Dylan Baker 57c8e1a780 run_mypy: add sourceset module 2022-02-23 10:18:34 -08:00
Dylan Baker 9b04257847 run_mypy: add gnome module 2022-01-18 21:58:24 -05:00
Dylan Baker fe51450970 depfile: type annotate 2022-01-10 23:06:20 -05:00
Jussi Pakkanen 69fa37e9ca
Merge pull request #9623 from dcbaker/submit/keyval-typeing
Add type annotations and typed_pos_args to the keyval module
2021-11-28 18:34:10 +02:00
Tristan Partin b361fc52dd Add typing to msubprojects.py 2021-11-28 07:10:12 -05:00
Dylan Baker e38c4defcb run_mypy: add modules/keyval 2021-11-23 13:20:40 -08:00
Dylan Baker cc231de08e modules/windows: use typed_kwargs 2021-10-09 21:34:48 -07:00
Dylan Baker 246d5f34bb run_mypy: Add the external_project_module 2021-10-04 19:33:43 -07:00
Daniel Mensinger ad65a699f9
docs: Initial reference manual generator 2021-10-03 11:46:34 +02:00
Dylan Baker bd2fcb268b modules/i18n: Fix remaining mypy spotted issues 2021-09-30 16:09:14 -07:00
Dylan Baker 92b21a0045 interpreter/mesonmain: Fix remaining typing problems and add to run_mypy 2021-09-24 10:36:05 -07:00
Daniel Mensinger 8d92e6d865 interpreter: Add IntegerHolder 2021-08-31 23:01:21 +02:00
Tristan Partin be92e37837 Add Java module
The Java module will serve as a source for easing Java development
within Meson. Currently it only supports generating native header files.
2021-08-22 07:57:29 -07:00
Dylan Baker a0e2de02bf run_mypy: add backends/backends 2021-08-20 18:57:19 +02:00