(options: list[BaseOptions])
| 211 | |
| 212 | |
| 213 | def create_matches(options: list[BaseOptions]) -> dict: |
| 214 | capabilities: dict[str, Any] = {"capabilities": {}} |
| 215 | opts = [opt.to_capabilities() for opt in options] |
| 216 | |
| 217 | # alwaysMatch holds only the capabilities that are present with an identical value in |
| 218 | # *every* option set; everything else stays in the per-option firstMatch entries. A |
| 219 | # candidate key must appear in every set, so it must appear in the first one; values |
| 220 | # may be dicts/lists and so are compared with ``==`` rather than placed in a set |
| 221 | # (see https://bugs.python.org/issue38210). |
| 222 | always: dict[str, Any] = {} |
| 223 | if opts: |
| 224 | for key, value in opts[0].items(): |
| 225 | if all(key in opt and opt[key] == value for opt in opts[1:]): |
| 226 | always[key] = value |
| 227 | |
| 228 | for opt_dict in opts: |
| 229 | for key in always: |
| 230 | del opt_dict[key] |
| 231 | |
| 232 | capabilities["capabilities"]["alwaysMatch"] = always |
| 233 | capabilities["capabilities"]["firstMatch"] = opts |
| 234 | |
| 235 | return capabilities |
| 236 | |
| 237 | |
| 238 | _P = ParamSpec("_P") |
no test coverage detected