Fix GP properties panel when built without experimental features #119752

Open
Sybren A. Stüvel wants to merge 1 commits from dr.sybren/blender:pr/fix-gpv3-when-disabled into main

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

Avoid accessing bpy.types.GreasePencilv3 class in the GP properties panel
when Blender was built without experimental features.

This uses a simple hasattr(bpy.types, "GreasePencilv3") as guard, as this
will keep working even when GPv3 is no longer experimental and we somehow
forgot to remove the guard.

Avoid accessing `bpy.types.GreasePencilv3` class in the GP properties panel when Blender was built without experimental features. This uses a simple `hasattr(bpy.types, "GreasePencilv3")` as guard, as this will keep working even when GPv3 is no longer experimental and we somehow forgot to remove the guard.
Sybren A. Stüvel added the
Module
Grease Pencil
label 2024-03-21 16:13:21 +01:00
Sybren A. Stüvel added 1 commit 2024-03-21 16:13:29 +01:00
Avoid accessing `bpy.types.GreasePencilv3` class in the GP properties panel
when Blender was built without experimental features.

This uses a simple `hasattr(bpy.types, "GreasePencilv3")` as guard, as this
will keep working even when GPv3 is no longer experimental and we somehow
forgot to remove the guard.
Sybren A. Stüvel requested review from Falk David 2024-03-21 16:13:42 +01:00
Falk David requested changes 2024-03-21 16:18:32 +01:00
Falk David reviewed 2024-03-21 16:23:16 +01:00
@ -249,0 +247,4 @@
if has_gpv3:
class DATA_PT_grease_pencil_custom_props(DataButtonsPanel, PropertyPanel, Panel):
_context_path = "object.data"
_property_type = bpy.types.GreasePencilv3
Member

I'm wondering if something like _property_type = bpy.types.GreasePencilv3 if hasattr(bpy.types, "GreasePencilv3") else None works? Since it will never try to draw the panel.

I'm wondering if something like `_property_type = bpy.types.GreasePencilv3 if hasattr(bpy.types, "GreasePencilv3") else None` works? Since it will never try to draw the panel.
Member

Or simpler: _property_type = getattr(bpy.types, "GreasePencilv3", None)

Or simpler: `_property_type = getattr(bpy.types, "GreasePencilv3", None)`
Author
Member

It might work, but there is no indication in the PropertyPanel code (and the functions it calls) that this property can safely be None. For example, when there is pinning involved the code isinstance(pin_id, property_type) will fail because None is not a type.

And even when it would work because of the effects of the mix-in classes, I still feel it would be very fragile. The approach in this PR, although significantly noisier, at least is more locally understandable.

It might work, but there is no indication in the `PropertyPanel` code (and the functions it calls) that this property can safely be `None`. For example, when there is pinning involved the code `isinstance(pin_id, property_type)` will fail because `None` is not a type. And even when it would work because of the effects of the mix-in classes, I still feel it would be very fragile. The approach in this PR, although significantly noisier, at least is more locally understandable.
This pull request has changes conflicting with the target branch.
  • scripts/startup/bl_ui/properties_data_grease_pencil.py

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u pr/fix-gpv3-when-disabled:dr.sybren-pr/fix-gpv3-when-disabled
git checkout dr.sybren-pr/fix-gpv3-when-disabled
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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#119752
No description provided.