From 46c53c25db8fed66705f0c84f630872d30db560a Mon Sep 17 00:00:00 2001 From: Philipp A Date: Mon, 13 Nov 2023 15:04:02 +0100 Subject: [PATCH] Backport PR #2750: Skip _wraps_plot_scatter on 3.9 --- scanpy/plotting/_tools/scatterplots.py | 33 +++++++------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/scanpy/plotting/_tools/scatterplots.py b/scanpy/plotting/_tools/scatterplots.py index 6c9441780a..f1bb904cc5 100644 --- a/scanpy/plotting/_tools/scatterplots.py +++ b/scanpy/plotting/_tools/scatterplots.py @@ -1,6 +1,6 @@ from __future__ import annotations -from collections import defaultdict +import sys import inspect import collections.abc as cabc from copy import copy @@ -578,31 +578,14 @@ def my_vmax(color_vector): np.percentile(color_vector, p=80) return tuple(out) -def _get_signature(obj: Any, *, eval_str: bool) -> inspect.Signature: - """inspect.signature wrapper with eval_str support on Python < 3.10""" - try: - from inspect import get_annotations - except ImportError: - from get_annotations import get_annotations - - sig_uneval = inspect.signature(obj) - annotations = defaultdict( - lambda: inspect.Signature.empty, get_annotations(obj, eval_str=eval_str) - ) - - parameters = [ - inspect.Parameter( - name, param.kind, default=param.default, annotation=annotations[name] - ) - for name, param in sig_uneval.parameters.items() - ] - - return inspect.Signature(parameters, return_annotation=annotations["return"]) - - def _wraps_plot_scatter(wrapper): - params = _get_signature(embedding, eval_str=True).parameters.copy() - wrapper_sig = _get_signature(wrapper, eval_str=True) + """Update the wrapper function to use the correct signature.""" + if sys.version_info < (3, 10): + # Python 3.9 does not support `eval_str`, so we only support this in 3.10+ + return wrapper + + params = inspect.signature(embedding, eval_str=True).parameters.copy() + wrapper_sig = inspect.signature(wrapper, eval_str=True) wrapper_params = wrapper_sig.parameters.copy() params.pop("basis")