TypeError: Callable() takes no arguments

# -*- coding: UTF-8 -*-
#Sentience 2.6

import typing

Ninf = typing.Callable[[int], bool]
Ninf_map = typing.Callable[[Ninf], bool]

def inj(k: int) -> Ninf:
    return lambda n: n < k

def eps(p : Ninf_map) -> Ninf:
    return lambda n: min(p(inj(k)) for k in range(n + 1))

def omniscience(p : Ninf_map) -> typing.Optional[Ninf]:
    return None if p(x := eps(p)) else x

s = omniscience(Ninf_map) == x

if s:
	print("XOXO")

I am writing this because I can’t seem to reference “x” using an argument for the function it’s in

Please help!

Please show the complete error message (complete traceback). I think it contains a line number and other information, right?

Please try to make the code easier to read:

  • Avoid single-space indentations - we usually use four spaces.
  • Separate function definitions by a blank line.
  • Remove redundant code - like expressions with no side-effect: inj, eps, omniscience

Traceback (most recent call last):
  File "compiler.py", line 16, in <module>
    s = omniscience(Ninf_map) == x
  File "compiler.py", line 12, in omniscience
    return None if p(x := eps(p)) else x
  File "/usr/lib/py/typing.py", line 624, in __call__
    result = self.__origin__(*args, **kwargs)
TypeError: Callable() takes no arguments

On the line 12 you are calling an abstract class Ninf_map assigned to the variable p. You cannot call an abstract class having an abstract __call__ method.

You can recreate exactly the same error on your Ninf* definitions using this shorter code:

Ninf = typing.Callable[[int], bool]
Ninf_map = typing.Callable[[Ninf], bool]

Ninf_map(None)

Reading through abc documentation rn
An example would be perfect

Abstract classes are used to act as parent classes to create subclasses. They are not supposed to be used directly.

typing.Callable exists to be used for typing annotations, not to be called as a function. You have to define a specific function to be called. You cannot call typing.Callable whose purpose is to be used just to describe a type of a function or other callable.

Oh. Gotcha…

If I can’t call the functions then how do I use the functions?

That may seem rhetorical…

You can call functions. typing.Callable is not a function.

2 Likes