# AssertionError: Unexpected callable

**URL:** <https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442>\
**Category:** Support\
**Created:** [January 5, 2021, 5:33pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442 "2021-01-05T17:33:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kc64](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/kc64/32/83_2.png) [@kc64](https://discourse.myhdl.org/u/kc64)\
**Post date:** [January 5, 2021, 5:33pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/1 "2021-01-05T17:33:42Z")

</div>

I get an `AssertionError: Unexpected callable` when I try converting my project. I’ve never seen this before that I recall and it does not provide any indication what might be the problem. Can any of you help?

```
from myhdl import *
from comparator import comparator

@block
def channel(reset, clock, data, count, enable, load_rising, load_falling, output):

	rising_edge = Signal(False)
	falling_edge = Signal(False)
	output = Signal(False)

	@always_seq(clock.posedge, reset=reset)
	def logic():
		rising_comparator = comparator(reset, clock, clear=False, load=load_rising, register_input=data, match_input=count, match=rising_edge)
		falling_comparator = comparator(reset, clock, clear=False, load=load_falling, register_input=data, match_input=count, match=falling_edge)
		if rising_edge and enable:
			output.next = True
		elif falling_edge:
			output.next = False
	return logic

WIDTH = 32
PERIOD = 20

def convert(hdl='Verilog'):

	clock = Signal(False)
	reset = ResetSignal(False, active=True, isasync=True)
	load_rising = Signal(False)
	load_falling = Signal(False)
	enable = Signal(False)
	output = Signal(False)

	data = Signal(intbv(0)[WIDTH:0])
	count = Signal(intbv(0)[WIDTH:0])

	inst = channel(reset, clock, data, count, enable, load_rising, load_falling, output)
	inst.convert(hdl=hdl)

if __name__ == ' __main__':
	convert()

```

* * *

```
(.venv) C:\project\source\pulser>py channel.py
Traceback (most recent call last):
  File "channel.py", line 135, in <module>
	convert()
  File "channel.py", line 130, in convert
	inst.convert(hdl=hdl)
  File "C:\project\.venv\lib\site-packages\myhdl\_block.py", line 342, in convert
	return converter(self)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_toVerilog.py", line 177, in __call__
	genlist = _analyzeGens(arglist, h.absnames)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_analyze.py", line 170, in _analyzeGens
	v.visit(tree)
  File "C:\python_v3.8.5\lib\ast.py", line 363, in visit
	return visitor(node)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_analyze.py", line 1070, in visit_Module
	self.generic_visit(node)
  File "C:\python_v3.8.5\lib\ast.py", line 371, in generic_visit
	self.visit(item)
  File "C:\python_v3.8.5\lib\ast.py", line 363, in visit
	return visitor(node)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_analyze.py", line 1141, in visit_FunctionDef
	self.visit(n)
  File "C:\python_v3.8.5\lib\ast.py", line 363, in visit
	return visitor(node)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_analyze.py", line 528, in visit_Assign
	self.visit(value)
  File "C:\python_v3.8.5\lib\ast.py", line 363, in visit
	return visitor(node)
  File "C:\project\.venv\lib\site-packages\myhdl\conversion\_analyze.py", line 656, in visit_Call
	raise AssertionError("Unexpected callable %s" % str(debug_info))
AssertionError: Unexpected callable [('id', 'comparator'), ('ctx', <_ast.Load object at 0x000001C6CCA75280>)]
```

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 5, 2021, 6:07pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/2 "2021-01-05T18:07:28Z")

</div>

I am afraid that the answer lies in comparator.py?

---

<div class="post-metadata">

**Author:** ![kc64](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/kc64/32/83_2.png) [@kc64](https://discourse.myhdl.org/u/kc64)\
**Post date:** [January 5, 2021, 6:16pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/3 "2021-01-05T18:16:06Z")

</div>

How did you derive at that? You must be better at parsing the traceback than I am. 🙂 Incidentally, the comparator code converts and functions correctly standalone.

```
# comparator.py

from myhdl import *

@block
def comparator(reset, clock, clear, load, register_input, match_input, match, WIDTH=32):

	register = Signal(intbv(0)[WIDTH:0])

	@always_comb
	def compare_logic():
		match.next = register == match_input

	@always_seq(clock.posedge, reset=reset)
	def compare_register():
		if clear:
			register.next = 0
		elif load:
			register.next = register_input

	return instances()
```

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 6, 2021, 8:13am UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/4 "2021-01-06T08:13:02Z")

</div>

The last trace line mentions _comparator_ so I assumed there may have been a problem there.  
The first trace line says that the error shows up when processing line 135 of your source file. I now assume the error lies inside your top-level module. But your snippet is a lot shorter …

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 6, 2021, 1:24pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/5 "2021-01-06T13:24:29Z")

</div>

The following lines must be moved outside the `logic` _process_ .

```auto
		rising_comparator = comparator(reset, clock, clear=False, load=load_rising, register_input=data, match_input=count, match=rising_edge)
		falling_comparator = comparator(reset, clock, clear=False, load=load_falling, register_input=data, match_input=count, match=falling_edge)

```

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 6, 2021, 1:27pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/6 "2021-01-06T13:27:47Z")

</div>

You’ll also have to add `rising_comparator` and `falling_comparator` to the return list.

---

<div class="post-metadata">

**Author:** ![kc64](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/kc64/32/83_2.png) [@kc64](https://discourse.myhdl.org/u/kc64)\
**Post date:** [January 6, 2021, 2:12pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/7 "2021-01-06T14:12:16Z")

</div>

Thanks to both of you for your kind and expert help. I moved the comparators out of the logic block and added them to the return list and it is now converting!

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 6, 2021, 6:13pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/8 "2021-01-06T18:13:12Z")

</div>

Oops, I should have seen that … I must be getting old 🙂

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 6, 2021, 8:25pm UTC](https://discourse.myhdl.org/t/assertionerror-unexpected-callable/442/9 "2021-01-06T20:25:41Z")

</div>

It took me some time to find the error. I’m a little less old 😉
