Page MenuHome

Python 4.0 delayed annotation evaluation (from __future__ import annotations )
Confirmed, LowPublicTO DO

Description

Short description of error
Adding
from __future__ import annotations
at the top of a python file makes the properties annotations of operators non-existent.

This will be enabled by default in Python 4.0, see: https://www.python.org/dev/peps/pep-0563

Exact steps for others to reproduce the error
Create and enable this simple demo addon:

from __future__ import annotations # this line makes the line 30 throw an error, because the property some_prop of BUGANNOTATIONS_OT_some_op will no longer exist

bl_info = {
	'name': 'Bug annotations with __future__',
	'author': 'Arnold, Arnaud Couturier, piiichan (couturier.arnaud@gmail.com)',
	'version': (1, 0, 0),
	'blender': (2, 80, 0),
	'location': 'scene options',
	'category': 'Scene',
}

import bpy


class BUGANNOTATIONS_OT_some_op(bpy.types.Operator):
	bl_idname = 'scene.hey'
	bl_label = 'An operator'
	some_prop: bpy.props.StringProperty(name='Hello', default='Default value')


class BUGANNOTATIONS_PT_some_panel(bpy.types.Panel):
	bl_region_type = 'WINDOW'
	bl_space_type = 'PROPERTIES'
	bl_context = 'scene'
	bl_options = {'DEFAULT_CLOSED'}
	bl_label = 'Bug annotations'

	def draw(self, context):
		op = self.layout.operator(BUGANNOTATIONS_OT_some_op.bl_idname)
		print(op.some_prop)


def register():
	bpy.utils.register_class(BUGANNOTATIONS_OT_some_op)
	bpy.utils.register_class(BUGANNOTATIONS_PT_some_panel)


def unregister():
	bpy.utils.unregister_class(BUGANNOTATIONS_PT_some_panel)
	bpy.utils.unregister_class(BUGANNOTATIONS_OT_some_op)

then go in the scene settings, a new panel appears. Show the button inside, and look into the console, you'll see that some_prop from the operator doesn't exist if future is imported.

Event Timeline

Campbell Barton (campbellbarton) renamed this task from from __future__ import annotations breaks operators properties annotations to Support for Python 4.0 delayed annotation evaluation (from __future__ import annotations).Apr 19 2019, 2:26 PM
Campbell Barton (campbellbarton) renamed this task from Support for Python 4.0 delayed annotation evaluation (from __future__ import annotations) to Python 4.0 delayed annotation evaluation (from __future__ import annotations).
Campbell Barton (campbellbarton) lowered the priority of this task from 90 to Low.
Campbell Barton (campbellbarton) edited a custom field.

Marking as TODO since it's not used unless you explicitly enable it and it's marked for inclusion in Python 4.0. - Added to T63733

Campbell Barton (campbellbarton) renamed this task from Python 4.0 delayed annotation evaluation (from __future__ import annotations) to Python 4.0 delayed annotation evaluation (from __future__ import annotations ).Apr 19 2019, 2:33 PM
Campbell Barton (campbellbarton) updated the task description. (Show Details)