Skip to content

Commit

Permalink
Merge pull request #170 from unihd-cag/159-handle-double-hex-prefix
Browse files Browse the repository at this point in the history
Handle double hex prefixes in remote object names
  • Loading branch information
TM90 authored Jan 12, 2022
2 parents 84bd10a + b13c447 commit 01bb527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions skillbridge/client/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ def __init__(self, channel: Channel, variable: str, translator: Translator) -> N

@property
def skill_id(self) -> int:
addr = self._variable[5:].rsplit('_', maxsplit=1)[1]
address = self._variable[5:].rsplit('_', maxsplit=1)[1]
try:
return int(addr, 0)
return int(address, 0)
except ValueError:
return int(addr, 16)
if address.startswith('0x0x'): # some skill objects have two '0x' in their name
address = address[2:]
return int(address, 16)

@property
def skill_parent_type(self) -> str:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ def test_lazy_list():
assert 'TEST~>shapes' in repr(l.shapes)

assert RemoteObject(channel, SkillCode('TESTTEST_123'), translator).lazy.shapes._variable == 'TESTTEST_123~>shapes'


def test_double_hex_prefix_does_not_crash():
assert RemoteObject(..., '__py_stuff_0x0xcafe', ...).skill_id == 0xcafe
assert RemoteObject(..., '__py_stuff_0xcafe', ...).skill_id == 0xcafe

0 comments on commit 01bb527

Please sign in to comment.