Message 370028 - Python tracker (original) (raw)
After trying to complete a patch, there are a few issues that immediately showed itself (and this might lead to not to do this in 3.10, I dont know);
First one is double-forward-ref, which is usage of string-annotations when there is postponed evaluatation of annotations:
import typing from future import annotations def x(a: 'int'): pass ... typing.get_type_hints(x) {'a': ForwardRef('int')}
If we make annoatations feature default, this would be default behavior. The solution would be a workaround to the compiler; static int compiler_visit_annexpr(struct compiler *c, expr_ty annotation) { if (annotation->kind == Constant_kind && PyUnicode_CheckExact(annotation->v.Constant.value)) { PyObject *text = annotation->v.Constant.value; Py_INCREF(text); ADDOP_LOAD_CONST_NEW(c, text); } else { ADDOP_LOAD_CONST_NEW(c, _PyAST_ExprAsUnicode(annotation)); } return 1; } But I am not sure if this is too silly or not.
The second problem is inspect.signature
. If we don't resolve annotations there and continue it is definitely going to break some code. If we resolve, that would mean that annotations must able to point something real (and this might not be the real case if the user uses a string annotation etc.) and will break code. (both tried and both breaks different modules on the stdlib tests)
The third problem is various dataclass hacks. Like _type_{field.name}
etc. annotations and how ClassVar/InitVar parsed.
There are also some little parts that need to change.
Any thoughts on these issues?