Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Support lazy type hint evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
olliesilvester committed Aug 21, 2023
1 parent 4e955ca commit 1ca5525
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ophyd_epics_devices/panda.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import atexit
import re
from enum import Enum
Expand Down Expand Up @@ -171,7 +173,7 @@ def _del_ctxt():

def verify_block(self, name: str, num: Optional[int]):
"""Given a block name and number, return information about a block."""
anno = get_type_hints(self).get(name)
anno = get_type_hints(self, globalns=globals()).get(name)

block: Device = Device()

Expand All @@ -194,7 +196,7 @@ async def _make_block(
"""
block = self.verify_block(name, num)

field_annos = get_type_hints(block)
field_annos = get_type_hints(block, globalns=globals())
block_pvi = await pvi_get(block_pv, self.ctxt) if not sim else None

# finds which fields this class actually has, e.g. delay, width...
Expand Down Expand Up @@ -266,7 +268,7 @@ def set_attribute(self, name: str, num: Optional[int], block: Device):
Need to be able to set device vectors on the panda as well, e.g. if num is not
None, need to be able to make a new device vector and start populating it...
"""
anno = get_type_hints(self).get(name)
anno = get_type_hints(self, globalns=globals()).get(name)

# if it's an annotated device vector, or it isn't but we've got a number then
# make a DeviceVector on the class
Expand All @@ -287,7 +289,7 @@ async def connect(self, sim=False) -> None:
pvi = await pvi_get(self._init_prefix + ":PVI", self.ctxt) if not sim else None
hints = {
attr_name: attr_type
for attr_name, attr_type in get_type_hints(self).items()
for attr_name, attr_type in get_type_hints(self, globalns=globals()).items()
if not attr_name.startswith("_")
}

Expand Down

0 comments on commit 1ca5525

Please sign in to comment.