Provide type annotations

Bug #1843791 reported by Daniel Hahler on 2019-09-12
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Beautiful Soup

Bug Description

It would be useful to have type annotations for bs4, to be used with mypy etc.

I've quickly generated them using "stubgen" [1] provided by mypy, and started adding some manually then - but nothing to publish really yet.

I've wondered if there are plans for this already, and thought it would be good to have an issue to discuss this / have a place for reference.

I've used "2to3" on the source before - not clear how this should be handled then when done in the repo itself.


Leonard Richardson (leonardr) wrote :

This is an interesting idea and I would like to get here eventually.

The sticking point, as you've found out, is that the canonical version of the Beautiful Soup code uses Python 2, and it's automatically converted to Python 3. I don't see a way to add these annotations without permanently switching to Python 3.

Because Beautiful Soup is frequently used in duct-tape environments I'm going to keep Python 2 support past the official end-of-life date, but eventually I will drop it, and we can pick up this issue then.

Changed in beautifulsoup:
status: New → Triaged
Daniel Hahler (blueyed) wrote :

So you plan to add them to the code directly already? (which is good!)

For Python 2 type hints could be used via comments, and hopefully get converted for the Python 3 version then also (still as comments then though).

btw: maybe it would be good to switch to Python 3 by default and auto-generate the Python 2 code then instead? But likely not worth the effort.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers