Skip to content

BS4 4.13 breaks internal typing #278

@facelessuser

Description

@facelessuser

BS4 now ships with type hints, but one particular change is wreaking havoc on our typing.

BS4 now returns PageElement for almost everything as Tags and Navigable strings both inherit from these. But these are distinctly different types with their own functions.

So right now, when we expect a Tag object or a NavigableString, we get an error because BS4 says it returns a PageElement.

We have functions that check is_tag etc., but mypy can't see figure this out and requires explicit inline checks for it to be able to figure stuff out. This is some of the pain of Python's typing system, it's helpful, but sometimes too dumb to be helpful in a meaningful sense. Anyway, we have a lot to fix because of this :(. I want to like typing so much, but stuff like this causes unnecessary churn. If only these tools were smart enough to see what was actually being used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: triageIssue needs triage.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions