What does clone return?

Issue #37 resolved
created an issue

I'm not sure if this is an bug or a documentation issue, but I'm unsure what clone does():



from pyquery import PyQuery d = PyQuery("<p>Hello World</p>") e = d.clone() e.html("What up") print d # Returns "<p>What up</p>" print e # Returns "<p>What up</p>" }}}

Should changing e modify d?

Comments (5)

  1. Anonymous

    I've just found some issues with clone myself. I think it only does a shallow clone—hence why edits are getting passed-on. I'm going to check to see if that's what jQuery does as well

  2. Anonymous

    Actually, seeing as the code was so simple, I had a crack at it—and fixed the bug!


    return PyQuery([deepcopy(tag) for tag in self])

    Instead of

    self[:] = [deepcopy(tag) for tag in self]
    return self

    It's probably not optimal, but it works.

    @btol45, it's your time to shine—clone the repo, patch the issue, and submit a pull request! (I'd do it myself but I don't have a BitBucket account, and I've only ever used Mercurial sparingly. Also, BitBucket accepting un–logged-in comments—so much win)

  3. Log in to comment