Skip to content
Snippets Groups Projects

Use beautifulsoup4 CSS selectors to simplify code and type checking

Merged Antoine Lambert requested to merge anlambert/swh-lister:add-bs4-type-checking into master

As the types-beautifulsoup4 package gets installed in the swh virtualenv as it is a swh-scanner test dependency, some mypy errors were reported related to beautifulsoup4 typing.

As the returned type for the find method of bs4 is the following union: Tag | NavigableString | None, isinstance calls must be used to ensure proper typing which is not great.

So prefer to use the select_one method instead where a simple None check must be done to ensure typing is correct as it is returning Optional[Tag]. In a similar manner, replace use of find_all method by select method.

It also has the advantage to simplify the code.

Merge request reports

Pipeline #8346 passed

Pipeline passed for 41407e0e on anlambert:add-bs4-type-checking

Merged by Antoine LambertAntoine Lambert 11 months ago (Apr 16, 2024 1:17pm UTC)

Loading

Pipeline #8352 passed

Pipeline passed for 41407e0e on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading