[issue23103] ipaddress should be Flyweight

Eric Snow report at bugs.python.org
Wed Dec 24 18:22:28 CET 2014


Eric Snow added the comment:

@sbromberger, there's no need for your own package.  Just use something like this:


_addr_cache = {}

def ipaddr(addr):
    try:
        return _addr_cache[addr]
    except KeyError:
        _addr_cache[addr] = ipaddress.ipaddress(addr)
        return _addr_cache[addr]


You could even throw weakrefs in there if your use case demanded it.

----------
nosy: +eric.snow

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23103>
_______________________________________


More information about the Python-bugs-list mailing list