Why does PyCharm complain that `Expected type 'Tag', got 'str' instead`?

Viewed 232

I have defined a variable offer which has the type of bs4.element.Tag. I have also defined a function get_price which scrapes the price from this tag and returns it as a string. When I run the following code:

def get_price(row: bs4.element.Tag) -> str:
    wrapper = row.find('td', class_='item_price')
    price = wrapper.find('span', class_='price')

    try:
        price_stripped = price.text.strip()
    except AttributeError:
        price_stripped = ''

    return price_stripped

print(type(row))
print(get_price(row))

I get

<class 'bs4.element.Tag'>
€25.00

which is the output I expected. However, why does PyCharm complain that Expected type 'Tag', got 'str' instead at the last line of my code? I'm confused as I believe I passed an object of type 'Tag' to get_price, so it doesn't make sense to me why PyCharm 'thinks' I passed it an object of type str.

0 Answers
Related