from . import schemaobj
from .. import util
from ..util import sqla_compat
+from ..util.compat import formatannotation_fwdref
from ..util.compat import inspect_formatargspec
from ..util.compat import inspect_getfullargspec
+
NoneType = type(None)
if TYPE_CHECKING:
name_args[0:2] = ["self"]
- args = inspect_formatargspec(*spec)
+ args = inspect_formatargspec(
+ *spec, formatannotation=formatannotation_fwdref
+ )
num_defaults = len(spec[3]) if spec[3] else 0
if num_defaults:
defaulted_vals = name_args[0 - num_defaults :]
spec[2],
defaulted_vals,
formatvalue=lambda x: "=" + x,
+ formatannotation=formatannotation_fwdref,
)
args = re.sub(
return ep.select(group=group)
else:
return ep.get(group, ())
+
+
+def formatannotation_fwdref(annotation, base_module=None):
+ """the python 3.7 _formatannotation with an extra repr() for 3rd party
+ modules"""
+
+ if getattr(annotation, "__module__", None) == "typing":
+ return repr(annotation).replace("typing.", "")
+ if isinstance(annotation, type):
+ if annotation.__module__ in ("builtins", base_module):
+ return annotation.__qualname__
+ return repr(annotation.__module__ + "." + annotation.__qualname__)
+ return repr(annotation)
--- /dev/null
+.. change::
+ :tags: bug, regression, ops
+ :tickets: 920
+
+ Fixed issue where registration of custom ops was prone to failure due to
+ the registration process running ``exec()`` on generated code that as of
+ the 1.7 series includes pep-484 annotations, which in the case of end user
+ code would result in name resolution errors when the exec occurs. The logic
+ in question has been altered so that the annotations are rendered as
+ forward references so that the ``exec()`` can proceed.