[Bf-blender-cvs] [e1900ddcfa7] master: Cleanup: use '_' prefix for internal bpy.ops variables

Campbell Barton noreply at git.blender.org
Thu Oct 8 08:57:05 CEST 2020


Commit: e1900ddcfa7c5468401838842a661d7bcdb17667
Author: Campbell Barton
Date:   Thu Oct 8 17:55:17 2020 +1100
Branches: master
https://developer.blender.org/rBe1900ddcfa7c5468401838842a661d7bcdb17667

Cleanup: use '_' prefix for internal bpy.ops variables

Even though these weren't included in __dir__, they are still accessible
from `vars(bpy.ops)`, use '_' to hint they are private.

===================================================================

M	release/scripts/modules/bpy/ops.py

===================================================================

diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py
index 39540ac08df..56346d453a2 100644
--- a/release/scripts/modules/bpy/ops.py
+++ b/release/scripts/modules/bpy/ops.py
@@ -19,23 +19,23 @@
 # <pep8-80 compliant>
 
 # for slightly faster access
-from _bpy import ops as ops_module
+from _bpy import ops as _ops_module
 
-# op_add = ops_module.add
-op_dir = ops_module.dir
-op_poll = ops_module.poll
-op_call = ops_module.call
-op_as_string = ops_module.as_string
-op_get_rna_type = ops_module.get_rna_type
-op_get_bl_options = ops_module.get_bl_options
+# op_add = _ops_module.add
+_op_dir = _ops_module.dir
+_op_poll = _ops_module.poll
+_op_call = _ops_module.call
+_op_as_string = _ops_module.as_string
+_op_get_rna_type = _ops_module.get_rna_type
+_op_get_bl_options = _ops_module.get_bl_options
 
-_ModuleType = type(ops_module)
+_ModuleType = type(_ops_module)
 
 
 # -----------------------------------------------------------------------------
 # Callable Operator Wrapper
 
-class BPyOpsSubModOp:
+class _BPyOpsSubModOp:
     """
     Utility class to fake submodule operators.
 
@@ -46,13 +46,13 @@ class BPyOpsSubModOp:
 
     def _get_doc(self):
         idname = self.idname()
-        sig = op_as_string(self.idname())
+        sig = _op_as_string(self.idname())
         # XXX You never quite know what you get from bpy.types,
         # with operators... Operator and OperatorProperties
         # are shadowing each other, and not in the same way for
         # native ops and py ones! See T39158.
         # op_class = getattr(bpy.types, idname)
-        op_class = op_get_rna_type(idname)
+        op_class = _op_get_rna_type(idname)
         descr = op_class.description
         return "%s\n%s" % (sig, descr)
 
@@ -101,8 +101,8 @@ class BPyOpsSubModOp:
         self._func = func
 
     def poll(self, *args):
-        C_dict, C_exec, _C_undo = BPyOpsSubModOp._parse_args(args)
-        return op_poll(self.idname_py(), C_dict, C_exec)
+        C_dict, C_exec, _C_undo = _BPyOpsSubModOp._parse_args(args)
+        return _op_poll(self.idname_py(), C_dict, C_exec)
 
     def idname(self):
         # submod.foo -> SUBMOD_OT_foo
@@ -123,30 +123,29 @@ class BPyOpsSubModOp:
         # NOTE: We only update active view-layer, since that's what
         # operators are supposed to operate on. There might be some
         # corner cases when operator need a full scene update though.
-        BPyOpsSubModOp._view_layer_update(context)
+        _BPyOpsSubModOp._view_layer_update(context)
 
         if args:
-            C_dict, C_exec, C_undo = BPyOpsSubModOp._parse_args(args)
-            ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
+            C_dict, C_exec, C_undo = _BPyOpsSubModOp._parse_args(args)
+            ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
         else:
-            ret = op_call(self.idname_py(), None, kw)
+            ret = _op_call(self.idname_py(), None, kw)
 
         if 'FINISHED' in ret and context.window_manager == wm:
-            BPyOpsSubModOp._view_layer_update(context)
+            _BPyOpsSubModOp._view_layer_update(context)
 
         return ret
 
     def get_rna_type(self):
         """Internal function for introspection"""
-        return op_get_rna_type(self.idname())
+        return _op_get_rna_type(self.idname())
 
     @property
     def bl_options(self):
-        return op_get_bl_options(self.idname())
+        return _op_get_bl_options(self.idname())
 
     def __repr__(self):  # useful display, repr(op)
-        # import bpy
-        return op_as_string(self.idname())
+        return _op_as_string(self.idname())
 
     def __str__(self):  # used for print(...)
         return ("<function bpy.ops.%s.%s at 0x%x'>" %
@@ -160,14 +159,14 @@ def _bpy_ops_submodule__getattr__(module, func):
     # Return a value from `bpy.ops.{module}.{func}`
     if func.startswith("__"):
         raise AttributeError(func)
-    return BPyOpsSubModOp(module, func)
+    return _BPyOpsSubModOp(module, func)
 
 
 def _bpy_ops_submodule__dir__(module):
     functions = set()
     module_upper = module.upper()
 
-    for id_name in op_dir():
+    for id_name in _op_dir():
         id_split = id_name.split("_OT_", 1)
         if len(id_split) == 2 and module_upper == id_split[0]:
             functions.add(id_split[1])
@@ -194,7 +193,7 @@ def __getattr__(module):
 
 def __dir__():
     submodules = set()
-    for id_name in op_dir():
+    for id_name in _op_dir():
         id_split = id_name.split("_OT_", 1)
 
         if len(id_split) == 2:



More information about the Bf-blender-cvs mailing list