Page MenuHome

No longer possible to inherit subclass properties (stored as annotations) in 2.8?
Closed, ArchivedPublic

Description

Here's an example, I have a set of operator classes used for rounding various object properties.
They all inherit from one subclass called RoundBase, which contains most of the code.
However, as the properties declared in the base class are not carried over, as subclasses do not inherit annotations.
I was surprised to find however that even this didn't work:

OBJECT_OT_RoundUVs.__annotations__.update(RoundBase.__annotations__)

Is there a way round this? If so, it would be appreciated if it were made clear in the API documentation.

Details

Type
Bug

Event Timeline

@Tom Wilson (hedgehog90) can you provide a simple example that does not work as expected?

Jacques Lucke (JacquesLucke) triaged this task as Needs Information from User priority.Jun 20 2019, 4:53 PM
class OBJECT_OT_RoundBase(bpy.types.Operator):
	bl_idname = 'object.round_base'
	bl_label = 'Round'
	bl_options = {'UNDO'}

	factor_xyz: bpy.props.FloatVectorProperty(
		name="Factor",
		default=(1.0, 1.0, 1.0),
		unit='LENGTH',
		subtype="XYZ"
	)

class OBJECT_OT_RoundVerts(OBJECT_OT_RoundBase):
	bl_idname = 'mesh.round_verts'
	bl_label = 'Round Verts'
	bl_options = {'REGISTER', 'UNDO'}

	def execute(self, context):
		print(self.factor_xyz) # produces error
		return {'FINISHED'}

OBJECT_OT_RoundVerts.__annotations__.update(OBJECT_OT_RoundBase.__annotations__) # running this before register_class doesn't work either.
Brecht Van Lommel (brecht) claimed this task.

You can't define subclasses this way, and it was problematic in 2.79 as well. You have to change it so OBJECT_OT_RoundBase is not a subclass of Operator, and OBJECT_OT_RoundVerts is a subclass of both OBJECT_OT_RoundBase and Operator.