Commit Graph

136 Commits

Author SHA1 Message Date
Xavier Claessens 567c96b68b typed_pos_args: Fix typo 2021-03-16 09:00:50 -04:00
Laurin-Luis Lehning f7dd111333 Some documentation language adjustments & improved error messages 2021-03-10 08:55:22 -05:00
Laurin-Luis Lehning 71e9909ffd Add tentative FeatureNew guard 2021-03-10 08:55:22 -05:00
Laurin-Luis Lehning 2607510b18 Add failing test cases & release snippet 2021-03-10 08:55:22 -05:00
Laurin-Luis Lehning 83c3c74510 Use interpreter exceptions instead of MesonException 2021-03-10 08:55:22 -05:00
Laurin-Luis Lehning 07f467d057 Switch fstring syntax to @..@ & limit fstring captures to int, str, float and bool 2021-03-10 08:55:22 -05:00
Laurin-Luis Lehning 130adef778 Add support for basic format strings 2021-03-10 08:55:22 -05:00
Tristan Partin c83106ee38 Add str.replace() method 2021-03-09 06:27:58 -05:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Dylan Baker b8e4600bb8 interpreterbase: fix ObjectHolder
There are two problems:
1. It doesn't take the generic type as a parameter
2. it sets subpproject to None, but expects to always get a string
2021-02-25 23:08:23 +02:00
Dylan Baker 8e73e5fe1c clarify some things in typed_pos_args
This uses some variables to simplify some logic, and updates the
docstring to be more useful.
2021-02-06 13:11:25 -05:00
Dylan Baker 2650977c38 interpreterbase: Add support for optional arguments to typed_pos_args
This allows representing functions like assert(), which take optional
positional arguments, which are not variadic. More importnatly you can
represent a function like (* means optional, but possitional):
```txt
func(str, *int, *str)
```

typed_pos_args will check that all of your types are correct, and if not
provide None, which allow simplifying a number of implementation details
2021-02-06 13:11:25 -05:00
Dylan Baker 978eeddab8 interpreterbase: Add support for variadic arguments to typed_pos_args
This allows functions like `files()` to be decorated.
2021-02-06 13:11:25 -05:00
Dylan Baker 0ead2e10db interpreterbase: Add a helper method for typing positional arguments
We don't do a very good job of type checking in the interpreter,
sometimes we leave it to the mid layers of backends to do that (layering
violations) and sometimes we just don't check them at all. When we do
check them it's a ton of boilerplate and complicates the code. This
should help quite a bit.
2021-02-06 13:11:25 -05:00
Antonin Décimo 39ede12aa5 Fix misspells
Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
2021-01-13 12:53:10 -05:00
Paolo Bonzini 4caa0577ec stabilize iteration order for dictionaries
The order of keys in dictionaries cannot be relied upon, because the hash
values are randomized by Python.  Whenever we iterate on dictionaries and
meson.build generates a list during the iteration, the different iteration
orders may cause random changes in the command line and cause ninja to
rebuild a lot of files unnecessarily.
2020-11-15 14:21:31 +01:00
Xavier Claessens 7176b74fd6 Add meson.project_build/source_root() methods 2020-09-28 11:22:38 -04:00
Daniel Mensinger 47373a2438
typing: get rid of most T.cast 2020-09-08 20:15:58 +02:00
Daniel Mensinger fb9738b8c7
typing: fully annotate mparser.py 2020-09-08 20:15:56 +02:00
Daniel Mensinger bb09ca9ad5
typing: fully annotate mesonlib.py 2020-09-08 20:15:56 +02:00
Daniel Mensinger ff28f3fa34
typing: completely type interpreterbase 2020-09-08 20:15:56 +02:00
Daniel Mensinger 9c1e72202d
typing: refactor dict handling 2020-09-08 20:15:55 +02:00
Xavier Claessens 70d2207212 interpreterbase: Fix typing annotation
Co-authored-by: Daniel Mensinger <daniel@mensinger-ka.de>
2020-09-02 12:55:31 -04:00
Xavier Claessens 9365486104 Special case meson.version().version_compare() statement
when that statement gets evaluated, the interpreter remembers the
version target and if it was part of the evaluation of a `if` condition
then the target meson version is temporally overriden within that
if-block.

Fixes: #7590
2020-09-02 12:55:31 -04:00
Elliot adfee4460a
prevent disabler() object from overwriting arrays (#7484)
* prevent disabler object from overwriting arrays

fixes #7107

* fix failing test

forgot that func() != func(void) in c
2020-08-18 07:07:59 -07:00
Zbigniew Jędrzejewski-Szmek 7ef51abfc5 Fix typo 2020-07-28 19:51:58 +02:00
Stéphane Cerveau 8f106a2b9a string: add substring method
This method aims to offer a simple way to 'substring'
an existing string with start and end values.
2020-07-20 20:04:01 -04:00
Dylan Baker d51551231f use FeatureNew.single_use
This is just slightly cleaner looking
2020-05-14 12:15:03 -07:00
Dylan Baker 21c8582d15 interpreterbase: Proxy extra_message through to feature_check_class 2020-05-14 12:15:03 -07:00
Dylan Baker e3b2f1b82f interpreterbase: Add a oneline helper method for Feature(New|Deprecated)
This allows us to replace FeatureNew(..).use() with just
FeatureNew.single_use(...). It's a lttle cleaner and hides some of the
smell.
2020-05-14 12:15:03 -07:00
Dylan Baker 4e9e35f3bd interpreterbase: Allow passing an extra message in feature/deprecation warnings
The intended use it to tell people the new thing to do.
2020-05-14 11:04:51 -07:00
Dylan Baker f29f3f9f28 interpreterbase: Fix version checking for deprecation
Currently deprecation features use the same logic as new features, but
that doesn't work correctly. FeatureNew wants to warn about cases where
you claim to support >= 0.40, but use a feature from 0.42; deprecation
wants to warn when you claim to support >= 0.50, but use a feature that
was replaced in 0.45.

To make this work we need to invert the version check in the deprecation
function, so that if the deprecation is 0.45, and the supported version
is >= 0.50, we get a true not a false.
2020-05-12 10:24:24 -07:00
Dylan Baker ee790eec2a interpreter: Don't assign duplication and new feature warning to the same variable
Currently The Deprecated and New features checkers share an attribute
through a base class that should be per class. We need to duplicate this
and move it into each of the sublcasses

Fixes #7080
2020-05-12 10:24:24 -07:00
James Hilliard d7c24ccddd Allow get_variable to still function when the fallback is a disabler. 2020-04-30 13:06:56 -07:00
Xavier Claessens 4d6faf6a13 interpreterbase: Add warning when built-in object method has no kwargs 2020-03-19 23:01:58 +02:00
Dylan Baker 1bb66d1568 fix conversion of hasattr to getattr
getattr() requires a default (return if missing) value or it raises an
AttributeError. In a few cases I changed hasattr to getattr and didn't
set a default value, so those cases could except. This corrects that.
2020-03-15 22:30:19 +02:00
Dylan Baker 1a82880730 mesonbuild/mesonlib: Add type annotations 2020-03-05 09:31:29 -08:00
Daniel Mensinger d67888bf9b
types: Remove redundant __init__() -> None annotation 2020-03-02 10:52:59 +01:00
Daniel Mensinger 0302a697b8
types: Use import typing as T 2020-03-02 10:51:07 +01:00
Daniel Mensinger ab988198c7
review: Initial fixup 2020-03-02 10:47:20 +01:00
Daniel Mensinger 5a89a6f804
types: (partially) annotate interpreterbase.py
This commit annotates most of interpreterbase.py. However,
there are stil the @wraps missing, since I am unsure what
the types are supposed to be here.
2020-03-02 10:42:43 +01:00
Daniel Mensinger c48b0dea27
types: Annotate ast/interpreter.py 2020-03-02 10:34:55 +01:00
Daniel Mensinger c14aea2812
types: Annotate mparser.py
This also fixes that the keys in ArgumentNode.kwargs are
all of the type BaseNode now. Before this commit, it was
possible that both strings and Nodes where used as keys.
2020-03-02 10:34:55 +01:00
Jon Turney 346b5c4be7
Store filename in node location
Warnings have a location node object (with subdir and lineno
attributes), which is passed as a location: kwarg to mlog.warning() and
formatted in _log_error().

Re-purpose the subdir attribute (path relative to the source root dir,
with an implied filename of 'meson.build'), which is stored into the
node by parser(), to contain a pathname.

(Properly I should rename 'subdir' -> 'file' everywhere, but that's a
lot of churn just to see if this works)

Notes:
The warning location node may also have a colno attribute, which is
currently ignored by _log_error().

We can't currently issue warnings with locations in meson_options.txt
because the filename isn't part of the location (as it's assumed to be
'meson.build).
2020-02-28 11:54:04 +00:00
Jon Turney 534a974da7
Adjust all the other places MesonException file attribute is set
A MesonException has file, lineno and colno attributes, which get
formatted as a location in mlog.exception().

The file attribute got changed from a path relative to the root source
directory to a pathname (absolute or relative to cwd) in one place in
commit b8fbbf59.  Adjust all the other places the file attribute is set
to match.

Also:
Setting MesonException.file seems to be missing in the case where Parser
returned a non-CodeBlockNode object.  Fortunately, that looks like it's
unreachable, but add it just in case.
2020-02-28 11:54:04 +00:00
Xavier Claessens 9b1a857473 dict: Fully evaluate keys
The only restriction is keys must be string after evaluation. This fix
various inconsistencies.
2019-12-04 16:45:56 -05:00
fchin 4e460f04f3 Fixed issue that the key's value type wasn't checked correctly.
Added two new failing tests.
2019-11-12 09:21:10 -05:00
franczc adb4e071e6 Adding dictionary entry using string variable as key. 2019-11-12 09:21:10 -05:00
Wolfgang Stöggl f037e7ef45 Fix typos found by codespell
- Typos were found by codespell v1.16.0
2019-11-06 09:55:30 -05:00
James Hilliard 2b6c997e33 Return a disabler when an unknown method is called on a disabler object 2019-10-24 23:57:31 +03:00