Use of the 'items' object in oh3 jython helper libraries

I’m migrating my jython rules from oh2 to 3 and have a problem with using the items object.
The first three log lines work, but the last line throws an exception: object has no attribute ‘testNum’

@rule("test")
@when("Item testNum changed")
def test(event):
    log.warn("testNum changed: {}".format(itemRegistry.getItem("testNum").state))
    log.warn("testNum changed: {}".format(ir.getItem("testNum").state))
    log.warn("testNum changed: {}".format(items["testNum"]))
    log.warn("testNum changed: {}".format(items.testNum))

This worked fine in oh2. Can someone say if it works for them in oh3?

That was removed from the Libraries late last year as it was problematic. The items object now only works like a dictionary.

OK. Thanks for letting me know. And thanks for the great work.
Another question if I may.
I’ve installed the Typing files from your repo, and also for the helper libraries, so in VSCode, ‘rule’, ‘when’ etc are known, but ‘items’, ‘itemRegistry’, ‘ir’ and others are unknown. Is this expected?
The code works ok, it’s just Pylance that cannot see them.

Read all of the documentation in the stubs repo, I cover how to do all of those things. Let me know if there is anything you don’t understand in there.

I read the documentation (again :slightly_smiling_face:). I guess I did not fully appreciate the ‘Usage’ section. It’s sinking in slowly.

I tried the example “In a Script” from that section, but it fails with

Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/personal/test2.py': ImportError: No module named typing in <script> at line number 1

Do I have to install ‘typing’ in Jython? How do I do that?

You can use them with or without installing the typing module. Instructions for both are in the docs.

I understand the use on the host running VSCode, the error I got was from running the script in openHAB

Hmm, I guess I need to clarify that then, thank you.

The choice to have typing installed or not applies to your OH installation in automation/lib/pytyon, not the system you are running VSCode on. The system you run VSCode on must have the typing library installed or you wouldn’t be getting any type hints.