Most aud Python module instance methods are documented as classmethods #108245

Closed
opened 2023-05-25 00:17:24 +02:00 by Thomas Barlow · 3 comments
Member

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.41

Blender Version
Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-05-24 15:26, hash: 9acff4edabe5
Worked: (newest version of Blender that worked as expected)

Short description of error
The aud module contains a number of classes that have their own functions. These functions have been documented as classmethod, implying that an instance of the class is not needed to call the function (e.g. aud.Device.lock()), however, most of the functions do need an instance of the class to be called because they are actually instance methods (e.g. my_device.lock() or less common aud.Device.lock(my_device)).

Exact steps for others to reproduce the error
The current documentation for the aud module can be found at https://docs.blender.org/api/current/aud.html

For a single example, run the following lines in the Python console:

  1. import aud
  2. print(aud.Device.lock.__doc__)
    • Observe that the documentation says it is a classmethod
  3. aud.Device.lock()
    • Observe that a TypeError occurs because the function is actually an unbound instance method and requires an instance to be passed as the first argument when called directly like this. If this function was a classmethod aud.Device would have been bound to the first argument automatically.

image

The below script can be run from the Text Editor to print to the console each function of a class in the aud module that claims to be a classmethod and whether this is actually the case:

import aud

class TestClass:
    @staticmethod
    def my_static_method(): ...
    
    @classmethod
    def my_class_method(cls): ...
    
    def my_instance_method(self): ...

def is_classmethod(clazz, m):
    # A classmethod when accessed from the class it belongs to will be bound to that class
    return getattr(m, "__self__", None) == clazz

assert not is_classmethod(TestClass, TestClass.my_static_method)
assert not is_classmethod(TestClass, TestClass.my_instance_method)
assert is_classmethod(TestClass, TestClass.my_class_method)

is_list = []
is_not_list = []
for attr_name in dir(aud):
    clazz = getattr(aud, attr_name)
    if not isinstance(clazz, type):
        continue

    for class_attr_name in dir(clazz):
        class_attr = getattr(clazz, class_attr_name)
        doc = getattr(class_attr, "__doc__", None)
        if not doc:
            continue
        if "classmethod" in doc:
            tup = (attr_name, class_attr_name)
            if is_classmethod(clazz, class_attr):
                is_list.append(tup)
            else:
                is_not_list.append(tup)

print()
print()

for attr_name, class_attr_name in is_list:
    print(f"Y aud.{attr_name}.{class_attr_name} is a classmethod")

print()

for attr_name, class_attr_name in is_not_list:
    print(f"N aud.{attr_name}.{class_attr_name} is not a classmethod")
**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.41 **Blender Version** Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-05-24 15:26, hash: `9acff4edabe5` Worked: (newest version of Blender that worked as expected) **Short description of error** The `aud` module contains a number of classes that have their own functions. These functions have been documented as `classmethod`, implying that an instance of the class is not needed to call the function (e.g. `aud.Device.lock()`), however, most of the functions do need an instance of the class to be called because they are actually instance methods (e.g. `my_device.lock()` or less common `aud.Device.lock(my_device)`). **Exact steps for others to reproduce the error** The current documentation for the `aud` module can be found at https://docs.blender.org/api/current/aud.html For a single example, run the following lines in the Python console: 1) `import aud` 1) `print(aud.Device.lock.__doc__)` - Observe that the documentation says it is a classmethod 1) `aud.Device.lock()` - Observe that a `TypeError` occurs because the function is actually an unbound instance method and requires an instance to be passed as the first argument when called directly like this. If this function was a `classmethod` `aud.Device` would have been bound to the first argument automatically. ![image](/attachments/cf7b5a29-81d7-46f1-8361-377bf4c63abc) The below script can be run from the Text Editor to print to the console each function of a class in the `aud` module that claims to be a `classmethod` and whether this is actually the case: ```py import aud class TestClass: @staticmethod def my_static_method(): ... @classmethod def my_class_method(cls): ... def my_instance_method(self): ... def is_classmethod(clazz, m): # A classmethod when accessed from the class it belongs to will be bound to that class return getattr(m, "__self__", None) == clazz assert not is_classmethod(TestClass, TestClass.my_static_method) assert not is_classmethod(TestClass, TestClass.my_instance_method) assert is_classmethod(TestClass, TestClass.my_class_method) is_list = [] is_not_list = [] for attr_name in dir(aud): clazz = getattr(aud, attr_name) if not isinstance(clazz, type): continue for class_attr_name in dir(clazz): class_attr = getattr(clazz, class_attr_name) doc = getattr(class_attr, "__doc__", None) if not doc: continue if "classmethod" in doc: tup = (attr_name, class_attr_name) if is_classmethod(clazz, class_attr): is_list.append(tup) else: is_not_list.append(tup) print() print() for attr_name, class_attr_name in is_list: print(f"Y aud.{attr_name}.{class_attr_name} is a classmethod") print() for attr_name, class_attr_name in is_not_list: print(f"N aud.{attr_name}.{class_attr_name} is not a classmethod") ```
Thomas Barlow added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-05-25 00:17:25 +02:00
Iliya Katushenock added the
Interest
Python API
label 2023-05-25 07:59:40 +02:00
Author
Member

I had a look through the source for aud and it looks like this documentation is coming from within extern/audaspace, so I'm not sure if I should be reporting this on https://github.com/neXyon/audaspace instead?

I had a look through the source for `aud` and it looks like this documentation is coming from within extern/audaspace, so I'm not sure if I should be reporting this on https://github.com/neXyon/audaspace instead?

I'm not sure if I should be reporting this on https://github.com/neXyon/audaspace instead?

It seems that the audaspace bug tracker is the recommended one now. As we can see in the link:

Bug reports and feature requests should go to the issue tracker.

But I will confirm in this tracker too for now.
@neXyon ^

> I'm not sure if I should be reporting this on https://github.com/neXyon/audaspace instead? It seems that the audaspace bug tracker is the recommended one now. As we can see in the link: > Bug reports and feature requests should go to the [issue tracker](https://github.com/audaspace/audaspace/issues). But I will confirm in this tracker too for now. @neXyon ^
Germano Cavalcante added
Module
VFX & Video
Status
Confirmed
Interest
Audio
and removed
Status
Needs Triage
labels 2023-05-25 18:59:49 +02:00
Joerg Mueller self-assigned this 2023-05-25 23:01:52 +02:00
Member

Fixed!

Fixed!
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-05-25 23:02:29 +02:00
Sign in to join this conversation.
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
3 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#108245
No description provided.