diff options
author | Bastien Montagne <b.mont29@gmail.com> | 2019-11-27 14:15:15 +0300 |
---|---|---|
committer | Bastien Montagne <b.mont29@gmail.com> | 2019-11-27 14:19:10 +0300 |
commit | eb798de101ac7946e2d719e763ad1f0fd3e26acd (patch) | |
tree | 1aa7f974879938404ead51fdb234bebe480e9e40 | |
parent | 3fa2b85bfd672156f7019252d00f8859c1bd5b22 (diff) |
Clean/Fix remaining cases of props assignments in resgistrable structs def.
We still had a few deprecated assignements of `bpy.props.xxx` to class
members in our API documentation and one of our py tests. Annotations
are to be used now.
Also remove the section about `register_module` utils, this has been
removed in 2.8.
Fix T71877: Python API overview sample code warning: class MyMaterialProps contains a property which should be an annotation!
Fix T71876: Python API overview references old bpy.utils.register_module function
-rw-r--r-- | doc/python_api/rst/info_overview.rst | 42 | ||||
-rw-r--r-- | tests/python/bl_pyapi_idprop_datablock.py | 17 |
2 files changed, 17 insertions, 42 deletions
diff --git a/doc/python_api/rst/info_overview.rst b/doc/python_api/rst/info_overview.rst index c960aecb292..e341453fe93 100644 --- a/doc/python_api/rst/info_overview.rst +++ b/doc/python_api/rst/info_overview.rst @@ -270,32 +270,6 @@ Using ``bl_idname = 1`` will raise. ``TypeError: validating class error: Operator.bl_idname expected a string type, not int`` -Multiple-Classes -^^^^^^^^^^^^^^^^ - -Loading classes into Blender is described above, -for simple cases calling :mod:`bpy.utils.register_class` (SomeClass) is sufficient, -but when there are many classes or a packages submodule has its own -classes it can be tedious to list them all for registration. - -For more convenient loading/unloading :mod:`bpy.utils.register_module` (module) -and :mod:`bpy.utils.unregister_module` (module) functions exist. - -A script which defines many of its own operators, panels menus etc. you only need to write: - -.. code-block:: python - - def register(): - bpy.utils.register_module(__name__) - - def unregister(): - bpy.utils.unregister_module(__name__) - -Internally Blender collects subclasses on registrable types, storing them by the module in which they are defined. -By passing the module name to :mod:`bpy.utils.register_module` -Blender can register all classes created by this module and its submodules. - - Inter Classes Dependencies ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -316,11 +290,11 @@ Say you want to store material settings for a custom engine. import bpy class MyMaterialProps(bpy.types.PropertyGroup): - my_float = bpy.props.FloatProperty() + my_float: bpy.props.FloatProperty() def register(): bpy.utils.register_class(MyMaterialProps) - bpy.types.Material.my_custom_props = bpy.props.PointerProperty(type=MyMaterialProps) + bpy.types.Material.my_custom_props: bpy.props.PointerProperty(type=MyMaterialProps) def unregister(): del bpy.types.Material.my_custom_props @@ -343,15 +317,15 @@ Say you want to store material settings for a custom engine. import bpy class MyMaterialSubProps(bpy.types.PropertyGroup): - my_float = bpy.props.FloatProperty() + my_float: bpy.props.FloatProperty() class MyMaterialGroupProps(bpy.types.PropertyGroup): - sub_group = bpy.props.PointerProperty(type=MyMaterialSubProps) + sub_group: bpy.props.PointerProperty(type=MyMaterialSubProps) def register(): bpy.utils.register_class(MyMaterialSubProps) bpy.utils.register_class(MyMaterialGroupProps) - bpy.types.Material.my_custom_props = bpy.props.PointerProperty(type=MyMaterialGroupProps) + bpy.types.Material.my_custom_props: bpy.props.PointerProperty(type=MyMaterialGroupProps) def unregister(): del bpy.types.Material.my_custom_props @@ -378,7 +352,7 @@ For example: .. code-block:: python # add a new property to an existing type - bpy.types.Object.my_float = bpy.props.FloatProperty() + bpy.types.Object.my_float: bpy.props.FloatProperty() # remove del bpy.types.Object.my_float @@ -388,14 +362,14 @@ This works just as well for PropertyGroup subclasses you define yourself. class MyPropGroup(bpy.types.PropertyGroup): pass - MyPropGroup.my_float = bpy.props.FloatProperty() + MyPropGroup.my_float: bpy.props.FloatProperty() ...this is equivalent to: .. code-block:: python class MyPropGroup(bpy.types.PropertyGroup): - my_float = bpy.props.FloatProperty() + my_float: bpy.props.FloatProperty() Dynamic Defined-Classes (Advanced) diff --git a/tests/python/bl_pyapi_idprop_datablock.py b/tests/python/bl_pyapi_idprop_datablock.py index c020f920eb2..648b63d1637 100644 --- a/tests/python/bl_pyapi_idprop_datablock.py +++ b/tests/python/bl_pyapi_idprop_datablock.py @@ -54,8 +54,8 @@ def abort_if_false(expr, msg=None): class TestClass(bpy.types.PropertyGroup): - test_prop = bpy.props.PointerProperty(type=bpy.types.Object) - name = bpy.props.StringProperty() + test_prop: bpy.props.PointerProperty(type=bpy.types.Object) + name: bpy.props.StringProperty() def get_scene(lib_name, sce_name): @@ -213,13 +213,14 @@ def test_restrictions1(): bl_idname = 'scene.test_op' bl_label = 'Test' bl_options = {"INTERNAL"} - str_prop = bpy.props.StringProperty(name="str_prop") + + str_prop: bpy.props.StringProperty(name="str_prop") # disallow registration of datablock properties in operators # will be checked in the draw method (test manually) # also, see console: # ValueError: bpy_struct "SCENE_OT_test_op" doesn't support datablock properties - id_prop = bpy.props.PointerProperty(type=bpy.types.Object) + id_prop: bpy.props.PointerProperty(type=bpy.types.Object) def execute(self, context): return {'FINISHED'} @@ -291,7 +292,7 @@ def test_regressions(): # test restrictions for datablock pointers def test_restrictions2(): class TestClassCollection(bpy.types.PropertyGroup): - prop = bpy.props.CollectionProperty( + prop: bpy.props.CollectionProperty( name="prop_array", type=TestClass) bpy.utils.register_class(TestClassCollection) @@ -299,9 +300,9 @@ def test_restrictions2(): class TestPrefs(bpy.types.AddonPreferences): bl_idname = "testprefs" # expecting crash during registering - my_prop2 = bpy.props.PointerProperty(type=TestClass) + my_prop2: bpy.props.PointerProperty(type=TestClass) - prop = bpy.props.PointerProperty( + prop: bpy.props.PointerProperty( name="prop", type=TestClassCollection, description="test") @@ -309,7 +310,7 @@ def test_restrictions2(): bpy.types.Addon.a = bpy.props.PointerProperty(type=bpy.types.Object) class TestUIList(UIList): - test = bpy.props.PointerProperty(type=bpy.types.Object) + test: bpy.props.PointerProperty(type=bpy.types.Object) def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): layout.prop(item, "name", text="", emboss=False, icon_value=icon) |