Merge ~facelessuser/beautifulsoup:bugfix/soupsieve into beautifulsoup:master

Proposed by Isaac Muse
Status: Merged
Merged at revision: a01835fcf30959eb286850b6c5fd1dd7ef52bd4c
Proposed branch: ~facelessuser/beautifulsoup:bugfix/soupsieve
Merge into: beautifulsoup:master
Diff against target: 140 lines (+40/-25)
2 files modified
bs4/css.py (+29/-8)
bs4/tests/test_css.py (+11/-17)
Reviewer Review Type Date Requested Status
Leonard Richardson Pending
Review via email: mp+437154@code.qastaging.launchpad.net

Commit message

Remove unnecessary test and don't pass namespace on precompiled select

Description of the change

Test that tries to run unknown soupsieve method no longer has
code associated with it, so the test is not needed.

If a precompiled pattern is passed into bs4, it should not pass
namespaces as the precompiled pattern already has that context
and can't be recompiled with new context.

To post a comment you must log in.
Revision history for this message
Isaac Muse (facelessuser) wrote :

So, I've reconsidered whether we need compile. I realize now that the compile object needs the documents namespace so as not to confuse users who expect it to be there. So compile should acquire this just like other methods unless the user specifically specifies it themselves.

Revision history for this message
Leonard Richardson (leonardr) wrote :

For the sake of my documentation, what's an example scenario where we need compile()?

Revision history for this message
Isaac Muse (facelessuser) wrote :

I think it is useful in the case where you have multiple things you need to target and handle differently, but you do not want to crawl the tree multiple times. In these cases you might utilize match, but using compile allows you to reuse the same pattern. We do cache patterns, but using compile will skip even having to retrieve the object from the cache and just reuse the existing pattern. The next Soup Sieve release will reduce overhead a little more when using a pre-compiled pattern.

Just some basic flow in which this would be used. Hopefully, that makes sense.

```
sel1 = soup.css.compile('some selector')
sel2 = soup.css.compile('some other selector')

# Iterate tags only
for el in soup.select('*'):
    # Do something different for different matches
    if el.match(sel1):
        # Do something
    elif el.match(sel2):
        # Do something else
```

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: