473,809 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

kwarg references

In the internal API when a C function is called and passed a kwarg
dictionary, is there any case where anything else has a reference to
it? I checked with the following code and it looks like even if you
explicitly pass a dictionary with **kwargs, it still copies the
dictionary anyway.

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Apr 25 '07 #1
2 3293
En Tue, 24 Apr 2007 22:31:59 -0300, Calvin Spealman <ir********@gma il.com>
escribió:
In the internal API when a C function is called and passed a kwarg
dictionary, is there any case where anything else has a reference to
it? I checked with the following code and it looks like even if you
explicitly pass a dictionary with **kwargs, it still copies the
dictionary anyway.
See the Python Reference Manual, 5.3.4 Calls
http://docs.python.org/ref/calls.html

Unfortunately it does not explicitely *guarantee* it will be a new
dictionary. At least the way I read the docs, on a function call like this:

def foo(**kwargs): pass
d = {'a':1, 'b':2)
foo(**d)

Python could bind the existing d object to the formal parameter kwargs and
still comply with the documented behavior. Some of my own code would break
if that happened... :(

--
Gabriel Genellina
Apr 26 '07 #2
Gabriel Genellina wrote:
En Tue, 24 Apr 2007 22:31:59 -0300, Calvin Spealman <ir********@gma il.com>
escribió:
>In the internal API when a C function is called and passed a kwarg
dictionary, is there any case where anything else has a reference to
it? I checked with the following code and it looks like even if you
explicitly pass a dictionary with **kwargs, it still copies the
dictionary anyway.

See the Python Reference Manual, 5.3.4 Calls
http://docs.python.org/ref/calls.html

Unfortunately it does not explicitely *guarantee* it will be a new
dictionary. At least the way I read the docs, on a function call like this:

def foo(**kwargs): pass
d = {'a':1, 'b':2)
foo(**d)

Python could bind the existing d object to the formal parameter kwargs and
still comply with the documented behavior. Some of my own code would break
if that happened... :(
The point is, of course, that inside the function you don't know whether
extra keyword arguments were provided as a part of a call with a
**kwargs argument or individually provided as kw1=value1. In the latter
case, obviously, there is no dict to choose whether to copy or not, so
the interpreter has no choice but to create a new dictionary.

On the one hand it would seem sensible to extend the definition of the
semantics so it is clear beyond doubt that mutating a **kwargs parameter
dictionary inside a function body does not change any dictionary that
was provided as a **argument, /even in the case where there is a
one-to-one correspondence between them/.

On the other hand it would also seem sensible to realise that this
latter case is so unusual that providing explicit semantics to support
it would take much more implementation work than always making a copy of
any **kw argument.

On the third hand, even *I* seem sensible sometimes so you just never
can tell :-)

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3085
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using pointers for my references to objects. There are 3 reasons why I find them inadequate: 1 - Can't be null. 2 - Can't be reseated. Now I'm sure there are good reasons for these first 2, but it's #3 that I
22
2255
by: xmp333 | last post by:
Hi All, I am trying to hide my JavaScript source. The method I chose was to keep all the important source in a password protected folder, and then use a SRC="folder/script.js" to include it in my code. This way, the script will run, but the user will be unable to view the included code. Or so I think :). I have tried this method, and it seems to work. However, I would like
33
2407
by: JKop | last post by:
I understand variables/objects and pointer variables perfectly: int X = 5; int* pX = &X; *pX = 4; int** ppX = &pX:
2
22298
by: S. van Beek | last post by:
Dear reader, For removing a reference in the VBA reference form I receive from Doug Steele the following code: ........... References.Remove refCurr
11
1996
by: codebloatation | last post by:
I know how to use references but i DO not get WHY they exist other than to add to the language. Are they actually needed for anything?
14
2968
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will utilise the disco file to update the Corresponding proxy file and reflect the changes made to the web service. However, the results of doing this with out params is that the results seem
30
2500
by: jeremygetsmail | last post by:
I've got an adp (Metrix.adp) with a reference to another adp (InteractSQL.adp). InteractSQL sits on a server, and is refered to by all of the clients (Metrix), which sit on the client machines (There's also a SQL Server that sits on the server, but that's besides the point here.). Both adp files have references to ADOX. I've got to check Metrix has an older version of ADOX, and react appropriately. I've written code to do this, and it...
9
2477
by: igor.kulkin | last post by:
References is a relatively basic feature of C++ language. It might be a good thing to think of references as aliases to the variables. However it's good to think of references this way when you deal with references which are local variables. But references can also be function arguments (in fact they are more useful this way) in which case it has to have the in-memory representation.
3
1356
by: Vladimir Rusinov | last post by:
Hello! I'm using beautiful soup html parser, and I need to get all '<div class=g>...</div>' tags. It can be done by: import BeautifulSoup as BSoup ...
0
9602
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10639
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.