summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-08-29 09:26:59 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2025-02-05 17:45:38 +0200
commitcd5bc11bb34054131e90a79d764383d55fefa330 (patch)
treebe518b7c50bd52230431e77e4f2ed7722a3b654b
parentb32e4e87b1c88eb235389c4f60f540154d720970 (diff)
downloadmeson-cd5bc11bb34054131e90a79d764383d55fefa330.tar.gz
options: Get rid of the invalid _U type, and use UserOption[_T]
-rw-r--r--mesonbuild/compilers/compilers.py15
-rw-r--r--mesonbuild/options.py8
2 files changed, 11 insertions, 12 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 424bcc19b..011dacfb7 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2012-2022 The Meson development team
-# Copyright © 2023-2024 Intel Corporation
+# Copyright © 2023-2025 Intel Corporation
from __future__ import annotations
@@ -20,9 +20,7 @@ from ..mesonlib import (
EnvironmentException, MesonException,
Popen_safe_logged, LibType, TemporaryDirectoryWinProof,
)
-
from ..options import OptionKey
-
from ..arglist import CompilerArgs
if T.TYPE_CHECKING:
@@ -37,9 +35,10 @@ if T.TYPE_CHECKING:
from ..dependencies import Dependency
CompilerType = T.TypeVar('CompilerType', bound='Compiler')
- _T = T.TypeVar('_T')
UserOptionType = T.TypeVar('UserOptionType', bound=options.UserOption)
+_T = T.TypeVar('_T')
+
"""This file contains the data files of all compilers Meson knows
about. To support a new compiler, add its information below.
Also add corresponding autodetection code in detect.py."""
@@ -216,19 +215,21 @@ clike_debug_args: T.Dict[bool, T.List[str]] = {
MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd']
+
@dataclass
-class BaseOption(T.Generic[options._T, options._U]):
- opt_type: T.Type[options._U]
+class BaseOption(T.Generic[_T]):
+ opt_type: T.Type[options.UserOption[_T]]
description: str
default: T.Any = None
choices: T.Any = None
- def init_option(self, name: OptionKey) -> options._U:
+ def init_option(self, name: OptionKey) -> options.UserOption[_T]:
keywords = {'value': self.default}
if self.choices:
keywords['choices'] = self.choices
return self.opt_type(name.name, self.description, **keywords)
+
BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = {
OptionKey('b_pch'): BaseOption(options.UserBooleanOption, 'Use precompiled headers', True),
OptionKey('b_lto'): BaseOption(options.UserBooleanOption, 'Use link time optimization', False),
diff --git a/mesonbuild/options.py b/mesonbuild/options.py
index d0cf231dc..ec1db8980 100644
--- a/mesonbuild/options.py
+++ b/mesonbuild/options.py
@@ -283,8 +283,6 @@ class UserOption(T.Generic[_T], HoldableObject):
self.value = self.validate_value(newvalue)
return self.value != oldvalue
-_U = T.TypeVar('_U', bound=UserOption[_T])
-
class UserStringOption(UserOption[str]):
def __init__(self, name: str, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING,
@@ -525,14 +523,14 @@ class UserStdOption(UserComboOption):
f'Possible values for option "{self.name}" are {self.choices}')
-class BuiltinOption(T.Generic[_T, _U]):
+class BuiltinOption(T.Generic[_T]):
"""Class for a builtin option type.
There are some cases that are not fully supported yet.
"""
- def __init__(self, opt_type: T.Type[_U], description: str, default: T.Any, yielding: bool = True, *,
+ def __init__(self, opt_type: T.Type[UserOption[_T]], description: str, default: T.Any, yielding: bool = True, *,
choices: T.Any = None, readonly: bool = False):
self.opt_type = opt_type
self.description = description
@@ -541,7 +539,7 @@ class BuiltinOption(T.Generic[_T, _U]):
self.yielding = yielding
self.readonly = readonly
- def init_option(self, name: 'OptionKey', value: T.Optional[T.Any], prefix: str) -> _U:
+ def init_option(self, name: 'OptionKey', value: T.Optional[T.Any], prefix: str) -> UserOption[_T]:
"""Create an instance of opt_type and return it."""
if value is None:
value = self.prefixed_default(name, prefix)