1

If I call QApplication's init without arguments i get

TypeError: arguments did not match any overloaded call:
  QApplication(list-of-str): not enough arguments
  QApplication(list-of-str, bool): not enough arguments
  QApplication(list-of-str, QApplication.Type): not enough arguments
  QApplication(Display, int visual=0, int colormap=0): not enough arguments
  QApplication(Display, list-of-str, int visual=0, int cmap=0): not enough arguments

very interesting! How can I write a class like that?? I mean, every trick for this kind of function overloading I saw did not involve explicit signatures.

2 Answers 2

3

TypeError is just another Exception. You can take *args **kwargs, check those, and raise a TypeError yourself, specify the text displayed - e.g. listing the expected call.

That being said, PyQt is a bunch of .pyd == native python extension, written in C or C++ (using Boost::Python). At least the latter supports "real" overloads afaik.

Either way, you shouldn't do this unless you have a really good reason. Python is duck-typed, embrace it.

Sign up to request clarification or add additional context in comments.

Comments

0

It's quite possible that its init is simply using __init__(self, *args, **kwargs) and then doing its own signature testing against the args list and kwargs dict.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.