Plugin parameters inspection for Python 3.14

With the release of Python 3.14, many runtime annotations can now be declared without strings. If they are evaluated then `NameError`s will occur.

Inspecting the callable signature of a plugin only requires the parameters' `name`s and `default`, so the annotations can be ignored and the inspection `annotation_format` can be set to `Format.STRING` (so long as `eval_str` is also `False` like it is by default).

See https://docs.python.org/3.14/library/inspect.html#inspect.signature & https://docs.python.org/3.14/library/annotationlib.html#annotationlib.Format.STRING
This commit is contained in:
Matt Norton 2025-10-09 18:26:02 +01:00 committed by GitHub
parent d45bdc05ce
commit c01786b035
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
"""Functions related to finding and loading plugins."""
from __future__ import annotations
import annotationlib
import configparser
import importlib.metadata
import inspect
@ -276,7 +277,9 @@ def _parameters_for(func: Any) -> dict[str, bool]:
parameters = {
parameter.name: parameter.default is inspect.Parameter.empty
for parameter in inspect.signature(func).parameters.values()
for parameter in inspect.signature(
func, annotation_format=annotationlib.Format.STRING
).parameters.values()
if parameter.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD
}