Moreover, static methods are now callable as regular functions.
(Contributed by Victor Stinner in :issue:`43682`.)
+* Annotations for complex targets (everything beside ``simple name`` targets
+ defined by :pep:`526`) no longer cause any runtime effects with ``from __future__ import annotations``.
+ (Contributed by Batuhan Taskaya in :issue:`42737`.)
+
New Modules
===========
...
async def g2(arg: {ann}) -> None:
...
+ class H:
+ var: {ann}
+ object.attr: {ann}
var: {ann}
var2: {ann} = None
+ object.attr: {ann}
"""
)
self.assertAnnotationEqual("('inf', 1e1000, 'infxxx', 1e1000j)", expected=f"('inf', {inf}, 'infxxx', {infj})")
self.assertAnnotationEqual("(1e1000, (1e1000j,))", expected=f"({inf}, ({infj},))")
+ def test_annotation_with_complex_target(self):
+ with self.assertRaises(SyntaxError):
+ exec(
+ "from __future__ import annotations\n"
+ "object.__debug__: int"
+ )
+
if __name__ == "__main__":
unittest.main()
--- /dev/null
+Annotations for complex targets (everything beside simple names) no longer
+cause any runtime effects with ``from __future__ import annotations``.
static int
check_annotation(struct compiler *c, stmt_ty s)
{
+ /* Annotations of complex targets does not produce anything
+ under annotations future */
+ if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
+ return 1;
+ }
+
/* Annotations are only evaluated in a module or class. */
if (c->u->u_scope_type == COMPILER_SCOPE_MODULE ||
c->u->u_scope_type == COMPILER_SCOPE_CLASS) {