Questions tagged [callable-object]

A callable object is an object which also can act as a function. Some languages allow arrays, hash tables or strings to be functions.

67 questions
3
votes
2 answers

Decorator "object is not callable"

I'm trying to get to grips with decorators in Python and trying to implement a version of the CachedProperty decorator from the botocore library, but keep hitting an error: TypeError: 'CachedProperty' object is not callable. I've been Googling…
Kaliklipper
  • 355
  • 5
  • 19
3
votes
1 answer

How to execute function if class instance is passed?

I currently have a TestClass that is callable. The callable executes a function that raises an exception if any attribute is equal to None. The purpose of defining it to be callable is so when TestClass instance is passed to another function or…
tyleax
  • 1,556
  • 2
  • 17
  • 45
3
votes
1 answer

Capturing generic callable objects in nested lambdas - always forward?

I have various functions in my codebase that take a generic callable object and pass it to a series of nested lambdas before calling it. Example: template void interface(TF&& f) { nested0([/*...*/]() { …
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
2
votes
3 answers

chaining callables in C++

I come from the python world where I could define a chain of operations and call them in a for loop: class AddOne: def __call__(self, x, **common_kwargs): return x+1 class Stringify: def __call__(self, x, **common_kwargs): …
Jav
  • 1,445
  • 1
  • 18
  • 47
2
votes
2 answers

Are pointer to member functions not callable object

I am reading C++ Primer 5th edition and there I came across the following statement: As a result, unlike ordinary function pointers, a pointer to a member is not a callable object; these pointers do not support the function-call operator. So my…
Jason
  • 36,170
  • 5
  • 26
  • 60
2
votes
1 answer

Check if class instances are callable without instantiating

How to check if the instances of a given class are callable? This is easy to do if you instantiate the class and then use callable(). But my question is how to check this without instantiating. Take for example the Calendar class: >>> import…
mauvilsa
  • 150
  • 1
  • 12
2
votes
1 answer

Null or None function in Python

I am using the CreateTrackBar function in OpenCV to create a trackbar. But I don't want any callback to happen on change. I will be doing that in a separate loop where I get the trackbar value using cv2.getTrackbarPos(). But Python returns an error…
abhigdeal
  • 162
  • 3
  • 9
2
votes
1 answer

How can I overload a function with a callable object as a parameter based on the object's call signature?

For example, given the following code class A { public: double operator()(double foo) { return foo; } }; class B { public: double operator()(double foo, int bar) { return foo + bar; } }; I want to write two…
2
votes
3 answers

emulating Clojure-style callable objects in Common Lisp

In Clojure, hash-maps and vectors implement invoke, so that they can be used as functions, for example (let [dict {:species "Ursus horribilis" :ornery :true :diet "You"}] (dict :diet)) lein> "You" or, for vectors, (let [v…
Daniel Shapero
  • 1,869
  • 17
  • 30
1
vote
0 answers

Is it possible to create a class ->Add, instance --> obj1 that can be called multiple times like the following : obj1(12)(34)(23)?

I am new to python and trying to create a class named Add that will have a modified call to make its objects act like functions and be callable multiple times like the following: class Adds: #def __call__(self): #code for addition obj1 =…
1
vote
0 answers

'NoneType' object is not callable, how to avoid errors?

TypeError Traceback (most recent call last) in 5 model_name = 'tuner007/pegasus_paraphrase' 6 torch_device = 'cuda' if torch.cuda.is_available() else 'cpu' ----> 7…
1
vote
0 answers

Create a callable button inside a view class discord.py

I want to create a callable button from a personalised button class. I have seen on this video that you can call button such as: @discord.ui.button(label="Hola") # Callback function that disable the button and reply to the user async def…
Ryarralk
  • 11
  • 4
1
vote
1 answer

how to set a trigger for when to record video open ai gym

I run multiple episodes, but only want to record for specific ones. More specifically, I'd like to have an input acting as trigger. Currently, my code is this: env = gym.make("HalfCheetah-v3") env = gym.wrappers.RecordVideo(env,…
Schach21
  • 412
  • 4
  • 21
1
vote
3 answers

How does one use an object as a function or how does one best create a custom callable object/type?

I have two file index.js and actor.js Index.js const {Actors} = import("./Actors"); const act1= new Actors({ name: 'Tony Stark', alias: 'Iron Man', gender: 'man', age: 38, powers: ["intelligence", "durability", "magnetism"] }) const…
1
vote
1 answer

What causes an exception in Tkinter callback?

I'm trying to make a program that you can add infinite rooms to, so all of my code is built around using one variable to deduce which room is which. However when I run it, it gives me an error that doesn't directly reference any one line in my code,…