PyDoc: clarify which classes support custom properties #120424

Open
Sybren A. Stüvel wants to merge 1 commits from dr.sybren/blender:pr/pydoc-customprop-support into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Update the list of classes that support custom properties. Instead of
presenting it as an exhaustive list (which by now has been quite
outdated), just list a few classes as example.

Update the list of classes that support custom properties. Instead of presenting it as an exhaustive list (which by now has been quite outdated), just list a few classes as example.
Sybren A. Stüvel added the
Module
Core
label 2024-04-09 13:30:44 +02:00
Sybren A. Stüvel added 1 commit 2024-04-09 13:30:52 +02:00
b840bd50ef PyDoc: clarify which classes support custom properties
Update the list of classes that support custom properties. Instead of
presenting it as an exhaustive list (which by now has been quite
outdated), just list a few classes as example.
Sybren A. Stüvel requested review from Campbell Barton 2024-04-09 13:31:14 +02:00

Since it's useful to know which types support ID properties, I think it might be more helpful to have a complete list of all classes that support ID properties & link to it. What do you think?

Since it's useful to know which types support ID properties, I think it might be more helpful to have a complete list of all classes that support ID properties & link to it. What do you think?
Author
Member

I agree that this would be nice, I'm just worried that it'll be outdated soon. Do you think there is a way to make the API doc generator aware of this, so that this can be automated?

I agree that this would be nice, I'm just worried that it'll be outdated soon. Do you think there is a way to make the API doc generator aware of this, so that this can be automated?

This can be done by checking bpy.types.bpy_struct_meta_idprop which supports __getitem__/__setitem__ access.

import bpy
bpy_struct_meta_idprop = bpy.types.bpy_struct_meta_idprop


def isinstance_direct(ty, ty_test):
    """
    Return true only when ``ty`` is a direct instance of ``ty_test``.
    """
    if not isinstance(ty, ty_test):
        return False
    for ty_base in ty.__bases__:
        # No need check `ty_base.__bases__` since `isinstance` does this.
        if isinstance(ty_base, ty_test):
            return False
    return True


for ty_name in dir(bpy.types):
    ty = getattr(bpy.types, ty_name)
    if not isinstance_direct(ty, bpy_struct_meta_idprop):
        continue

    print("bpy.types." + ty.__name__)

A list of these types can be added to generated docs, e.g. https://docs.blender.org/api/4.2/idprop.types.html then linked from methods that deal with id-properties as well as https://docs.blender.org/api/4.2/info_quickstart.html#custom-properties.

This can be done by checking `bpy.types.bpy_struct_meta_idprop` which supports `__getitem__/__setitem__` access. ```python import bpy bpy_struct_meta_idprop = bpy.types.bpy_struct_meta_idprop def isinstance_direct(ty, ty_test): """ Return true only when ``ty`` is a direct instance of ``ty_test``. """ if not isinstance(ty, ty_test): return False for ty_base in ty.__bases__: # No need check `ty_base.__bases__` since `isinstance` does this. if isinstance(ty_base, ty_test): return False return True for ty_name in dir(bpy.types): ty = getattr(bpy.types, ty_name) if not isinstance_direct(ty, bpy_struct_meta_idprop): continue print("bpy.types." + ty.__name__) ``` A list of these types can be added to generated docs, e.g. https://docs.blender.org/api/4.2/idprop.types.html then linked from methods that deal with id-properties as well as https://docs.blender.org/api/4.2/info_quickstart.html#custom-properties.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u pr/pydoc-customprop-support:dr.sybren-pr/pydoc-customprop-support
git checkout dr.sybren-pr/pydoc-customprop-support
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120424
No description provided.