Page MenuHome

Python error when using lambda for poll function and annotations from future
Closed, ResolvedPublic

Description

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: Quadro 600/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 369.09

Blender Version
Broken: version: 2.93.0 Alpha, branch: master, commit date: 2021-03-05 20:45, hash: rBbecc36cce524
Worked: version: 2.93.0 Alpha, branch: master, commit date: 2021-02-20 05:19, hash: rB37e6a1995ac7

caused by rB08dbc4f996e4: PyAPI: use postponed annotations to support Python 3.10

Short description of error
The UI element which should allow the user to select which Camera to use as the adaptive subdivision dicing camera no longer functions. This seems like a recent regression in the past 2 weeks.

Exact steps for others to reproduce the error

  • Start with default scene
  • Enable Cycles, Experimental
  • Go to the Subdivision properties under Cycles and attempt to select a Dicing Camera
  • Observe that nothing is listed even when adding new cameras to the scene, not even the default camera is listed

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Mar 6 2021, 10:20 AM
Philipp Oeser (lichtwerk) claimed this task.

Confirmed, will check

It is caused by rB08dbc4f996e4: PyAPI: use postponed annotations to support Python 3.10

I am getting this now:

Traceback (most recent call last):
  File "/build_linux/bin/2.93/scripts/modules/bpy_types.py", line 783, in draw_ls
    operator_context_default = self.layout.operator_context
AttributeError: 'CyclesRenderSettings' object has no attribute 'layout'

dicing_camera is using a lambda for its poll, thought that might be the reason, but so does e.g. the Sun Position Addon [and there it is working properly].

Philipp Oeser (lichtwerk) triaged this task as High priority.Mar 6 2021, 12:41 PM
Philipp Oeser (lichtwerk) updated the task description. (Show Details)

but so does e.g. the Sun Position Addon [and there it is working properly].

that does not do the following though

from __future__ import annotations

it is probably more effective if @Campbell Barton (campbellbarton) has a look here.

Brecht Van Lommel (brecht) reopened this task as Confirmed.Mar 12 2021, 5:55 PM

I committed a workaround, but I don't know if there is a deeper issue here in the Python API or Python itself. I'll leave it to the Python module to decide if they want to look into this further.

I guess that : from the lambda somehow messes with annotation parsing? Still not clear to me how that ends up affecting the GenericUI class.

dicing_camera: PointerProperty(                                                                             
    name="Dicing Camera",
    type=bpy.types.Object,
    poll=lambda self, obj: obj.type == 'CAMERA',                                                            
)
Brecht Van Lommel (brecht) renamed this task from Cycles dicing camera is not settable in the UI to Python error when using lambda for poll function and annotations from future.Mar 12 2021, 5:55 PM
Brecht Van Lommel (brecht) removed Brecht Van Lommel (brecht) as the assignee of this task.