What does clone return?

btol45 avatarbtol45 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!

    Use

    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. Caleb Burns

    I cloned, patched, and made a pull request for this issue. For a quick fix until the patch is accepted do

    cloned = PyQuery(original).clone()
    
  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.