About 1,720,000 results
Open links in new tab
  1. python - What is a "callable"? - Stack Overflow

    Apr 7, 2017 · A callable is an object allows you to use round parenthesis ( ) and eventually pass some parameters, just like functions. Every time you define a function python creates a callable object. In example, you could define the function func in these ways (it's the same):

  2. what exactly is python typing.Callable? - Stack Overflow

    Jul 30, 2024 · typing.Callable is the type you use to indicate a callable. Most python types that support the operator are of the type collections.abc.Callable. Examples include functions, classmethods, staticmethods, bound methods and lambdas. In summary, anything with a __call__ method (which is how is implemented), is a callable.

  3. python - Check if an object is callable - Stack Overflow

    What is the new way of checking "callable" methods in python 3.x? 0. Python: listing callable objects? 14.

  4. python - What does it mean for a class to be callable? - Stack …

    Leaving apart the mechanisms that mark functions as callable, Python classes have, as you know, special methods. The method that makes instances of a class callable is __call__. So, if your class has an explicit __call__ method, its instances are callable and end of story: when you call the instance, it is the __call__ method that is called.

  5. python - TypeError: 'module' object is not callable - Stack Overflow

    Dec 17, 2022 · It seems like what you've done is imported the socket module as import socket.Therefore socket is the module. You either need to change that line to self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM), as well as every other use of the socket module, or change the import statement to from socket import socket.

  6. python - making a class callable in same instance - Stack Overflow

    Jan 29, 2013 · To make a class instance callable, all you need to do is implement a __call__ method. Then, to call the __call__ method, you just do: instance(arg1,arg2,...)-- in other words, you call the instance the same way you would call a function.

  7. How can I specify the function type in my type hints?

    Jun 15, 2016 · As @jonrsharpe noted in a comment, this can be done with collections.abc.Callable: from collections.abc import Callable def my_function(func: Callable): Note: Callable on its own is equivalent to Callable[..., Any]. Such a Callable takes any number and type of arguments (...) and returns a value of any type (Any). If this is too unconstrained ...

  8. python - types.FunctionType vs typing.Callable? - Stack Overflow

    However, this functionality is deliberately limited: doing isinstance(f, Callable[[int, int], str]) is intentionally disallowed. Attempting to perform that check will raise an exception at runtime. Attempting to perform that check will raise an exception at runtime.

  9. Python type hinting for async function as function argument

    Mar 19, 2018 · Callable - something which can be invoked with (), ... stands for any argument, and it produces: Coroutine[Any, Any, Any] - this is copied from OP, and very general. You suggest that this function_ may be await -ed, but also receive stuff send() -ed by consumer , and be next() …

  10. python - TypeError: 'int' object is not callable - Stack Overflow

    Mar 19, 2023 · Given the following: a = 23 b = 45 c = 16 round((a/b)*0.9*c) Running the above outputs an error: TypeError: 'int' object is not callable.

Refresh