Is this bad practice to do inside an __init__ method?

I ask incase it makes the code harder to read by doing this for some reason. in my opinion it makes my classes look a lot cleaner

    def __init__(self, html: str):
        self.parser = BeautifulSoup(markup=html, features='lxml')
        self.css = self.find_attr(query='href', attrs={'type': 'text/css'})
        self.font = self.find_attr(
            query='href', attrs={'type': re.compile('font/*')})
        self.script = self.find_attr(
            query='src', attrs={'type': 'text/javascript'})
        self.anchor = self.find_attr(tag='a', query='href')
        self.page_path = [self._has_path(tag) for tag in self.anchor]
        self.page_fragment = [self._has_fragment(tag) for tag in self.anchor]
1 Like

Uh I don’t see anything directly wrong there, so maybe pointing out what your concern is might help.

If your asking about just performing some logic to get values for your instance attributes, then no, nothing wrong with it at all. I personally would only be careful about performing a lot of code in the __init__ method, but here you have mostly 1 liners/method calls, which should be fine.