mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 07:14:18 +00:00
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:
parent
d45bdc05ce
commit
c01786b035
1 changed files with 4 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"""Functions related to finding and loading plugins."""
|
"""Functions related to finding and loading plugins."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import annotationlib
|
||||||
import configparser
|
import configparser
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
import inspect
|
import inspect
|
||||||
|
|
@ -276,7 +277,9 @@ def _parameters_for(func: Any) -> dict[str, bool]:
|
||||||
|
|
||||||
parameters = {
|
parameters = {
|
||||||
parameter.name: parameter.default is inspect.Parameter.empty
|
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
|
if parameter.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue