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 6128623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:52+00:00 2026-05-23T16:38:52+00:00

I got a pretty weird behaviour with the decorator library which is explained in

  • 0

I got a pretty weird behaviour with the decorator library which is explained in the next code:

from decorator import decorator    

@decorator
def wrap(f, a, *args, **kwargs):
    print 'Decorator:', a, args, kwargs
    return f(a, *args, **kwargs)

def mywrap(f):
    def new_f(a, *args, **kwargs):
        print 'Home made decorator:', a, args, kwargs
        return f(a, *args, **kwargs)
    return new_f

@wrap
def funcion(a, b, *args, **kwargs):
    pass

@mywrap
def myfuncion(a, b, *args, **kwargs):
    pass

funcion(1, b=2)
myfuncion(1, b=2)

The execution of this script prints:

$ python /tmp/test.py 
Decorator: 1 (2,) {}
Home made decorator: 1 () {'b': 2}

‘decorator’ hides the kwargs inside the args, how can I solve this without using a “home made” decorator.

Thanks.

  • 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-23T16:38:52+00:00Added an answer on May 23, 2026 at 4:38 pm

    Just because you call the function with b=2 does not make b a keyword argument; b is a positional argument in the original function. If there were no argument named b and you specified b=2, then b would become a keyword argument.

    decorator‘s behavior is actually the most correct; the wrapper it generates has the same signature as funcion(), whereas the wrapper made by your “homemade” decorator does not have b as a named argument. The “homemade” wrapper “incorrectly” puts b in kwargs because the signature of myfuncion(), which makes it clear that b is not a keyword arg, is hidden from the caller.

    Preserving the function signature is a feature, not a bug, in decorator.

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

Sidebar

Related Questions

I've got a flex component which works pretty well but unfortunately turns into a
I've got a pretty much vanilla install of SOLR 1.4 apart from a few
I've got a list with paragraphs in it, yet it's displaying pretty weird in
I got a pretty simple parent/child relationship here, which looks like this: Email servers
It's pretty weird, but i got my PATH corrupted after installing rvm on Mac
I've got a weird error when trying to generate database from an EF model.
I've got a pretty good working snippit of code, but I was wondering if
I've got a pretty weird issue and can't find a solution. These two pictures
I got pretty experienced with testing controllers, my question here is though, aren't we
I'm working on an MFC application, that got pretty messy over years and over

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.