Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5965955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:02+00:00 2026-05-22T19:43:02+00:00

I’m having trouble understanding why Python raises a TypeError when you provide arguments that

  • 0

I’m having trouble understanding why Python raises a TypeError when you provide arguments that aren’t part of a method signature.

Example:

>>> def funky():
...    pass
... 
>>> funky(500)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: funky() takes no arguments (1 given)

I thought, if this is because *args is expected to be None or [] within the scope of a no-arg function, that’s a leaky abstraction, so I looked it up.

What I found

A page search for TypeError on PEP-3102 found what appeared to be justification for one context in which TypeError is raised, but I don’t understand the justification. The PEP’s example is essentially stating that the functionality is basically a shortcut for if args: raise TypeError(). args is a non-empty list in that case as opposed to an empty list… which are both of the same type. If I’m not mistaken and that is indeed the justification, perhaps a ValueError would be more appropriate. However, that would still be sort-of a leaky abstraction since the example is written in Python, making it more of an implementation detail of a certain use case than a language feature. Something like ArgumentError sounds much more appropriate here to me, which leads me to believe there is some obvious explanation that I missed as to why TypeError makes sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:43:04+00:00Added an answer on May 22, 2026 at 7:43 pm

    The function takes n arguments. You provided m. n != m. That’s propably a bug in someone’s code or a symptom of someone’s misunderstanding of some API. Also, I don’t think we could agree on meaningful, useful semantics what should happen in this case. Should superfluous arguments be ignored? That would let such bugs pass, and since “errors shall never pass silently”, that’s not acceptable. Similarily, supplying some default value for omitted arguments permits silent misbehaviour in the case of typos etc. and thus violates the same principle, not to mention that “explicit is better than implicit”, i.e. if you want to pass some special value you should just write that out.

    The PEP you refer to and it’s if args: raise TypeError(...) semantics apply only to functions with keyword-only arguments that don’t accept varargs and use a plain * in the parameter list to codify this. There are functions that accept a limited number of positional arguments and would benefit from keyword-only arguments but varargs wouldn’t be meaningful for them. For these, plain * exists to allow keyword-only arguments without requiring boilerplate code and still notify the programmer in case someone provides too many arguments (which is a good thing for reasons listed in the first part of the answer).

    As for why TypeError was chosen: “Wrong number of arguments” is a compiletime type error/type mismatch in static languages. We don’t have compiletime checking for such things in Python, but it’s still kind of a “type error”. If the (in Python, informal) type signature says “I take two arguments” and you provide three, that’s obviously a violation of that contract. TypeError doesn’t just mean not isinstance(x, expected), like much other typing-related topics (just think inheritance and “gets parent’s stuff” vs. “is-a parent”) it’s a much broader concept.

    Edit in response to your criticism of the static typing comparision: Considering an unary function different from a binary function isn’t just an abritary limitation of static type systems. It’s very useful even in languages like Python, since the two aren’t similar enough to be used “as if they walked and quacked alike” (as in duck typing) – they can’t be used in the same way. (The exception, metaprogramming which wraps functions of abritary arity, is handled by the * and ** unpacking operators.) They happen to share the fact that they’re callable, but they’re incompatible even if Python’s builtin object hierarchy doesn’t create numerous identical classes that only differ in arity and thus name. type(f) may say function, but that’s not always the end of the story.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string
I'm trying to create an if statement in PHP that prevents a single post
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.