New submission from Nick Coghlan: I've been tinkering with the ipaddress module as I review Eli's documentation and have uncovered a *very* nasty interaction between ipaddress objects and the bytes constructor.
Specifically, if you pass an integer to bytes() it will attempt to allocate and zero-initialise a buffer of that size. It uses operator.index() to check for integers. This creates a problem, because ipaddress objects currently implement __index__ so they can be treated as integers without an explicit cast. This does very bad things if, say, you do "bytes(ipaddress.IPv4Address('192.168.0.1'))" If I remove the __index__ implementation, then you can't call hex() directly on ipaddress objects anymore - you have to call hex(int(addr)) instead. I'm a *lot* happier with that approach, and will be implementing it in a moment. ---------- messages: 167474 nosy: georg.brandl, ncoghlan, pmoody priority: release blocker severity: normal status: open title: Bad interaction between ipaddress addresses and the bytes constructor type: crash _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15559> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com