How to type hint a bs4.BeautifulSoup object as a return type in a python function?

Viewed 56

First question on StackOverflow and I'm hoping it's not a dumb one.

Is there a type hint norm for bs4.objects? I have a function that is returning a bs4 object (specifically the standard "soup" object of a page passed into bs4). I want to state that's what the expected return is, but I can't just put bs4.BeautifulSoup without getting a name error (no surprise there). I like to typehint my code, but there doesn't seem to be a good answer anywhere online. I appreciate any advice people have here.

async def emb_soup(embassy_home: str) -> bs4.BeautifulSoup: 

obviously this didn't work, but it's an example of what I'm looking for

1 Answers

Nevermind, I figured a way out. I was making a mistake in my library importation. By not importing bs4 (not strictly necessary for what I'm doing), I can't type hint with it. Simple work around of importing bs4. This has a possible downside of importing a library I'm not really using, but I can live with it.

import bs4

It really was that simple; I was just overthinking/complicating it.

Related