Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed
    iscode = False
    if isinstance(mobject, Text):
        mobject = mobject[:]
    elif isinstance(mobject, Code):
        iscode = True
        code = mobject
        mobject = mobject.code
    mobject_without_dots = VGroup()
    if mobject[0].__class__ == VGroup:
        for i in range(len(mobject)):
            mobject_without_dots.add(VGroup())
            mobject_without_dots[i].add(*(k for k in mobject[i] if k.__class__ != Dot))
    else:
        mobject_without_dots.add(*(k for k in mobject if k.__class__ != Dot))
    if iscode:
        assert isinstance(code, Code)
        code.code = mobject_without_dots
        return code
    return mobject_without_dots


class Paragraph(VGroup):
    r"""Display a paragraph of text.

    For a given :class:`.Paragraph` ``par``, the attribute ``par.chars`` is a
    :class:`.VGroup` containing all the lines. In this context, every line is
    constructed as a :class:`.VGroup` of characters contained in the line.



Review comment (refactor):
In the same way you refactored the code above to use the cleaner `isinstance`, I suggest doing the same with the code below (I also suggest directly iterating over the submobjects of `mobject` rather than over indices):
```py
    mobject_without_dots = VGroup()
    if isintance(mobject[0], VGroup):
        for submob in mobject:
            mobject_without_dots.add(VGroup(k for k in submob if not isinstance(k, Dot)))
    else:
        mobject_without_dots.add(*(k for k in mobject if not isinstance(k, Dot)))
```

Code after:
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed
    iscode = False
    if isinstance(mobject, Text):
        mobject = mobject[:]
    elif isinstance(mobject, Code):
        iscode = True
        code = mobject
        mobject = mobject.code
    mobject_without_dots = VGroup()
    if isinstance(mobject[0], VGroup):
        for submob in mobject:
            mobject_without_dots.add(
                VGroup(k for k in submob if not isinstance(k, Dot))
            )
    else:
        mobject_without_dots.add(*(k for k in mobject if not isinstance(k, Dot)))
    if iscode:
        assert isinstance(code, Code)
        code.code = mobject_without_dots
        return code
    return mobject_without_dots


class Paragraph(VGroup):
    r"""Display a paragraph of text.

    For a given :class:`.Paragraph` ``par``, the attribute ``par.chars`` is a
    :class:`.VGroup` containing all the lines. In this context, every line is
    constructed as a :class:`.VGroup` of characters contained in the line.


    Parameters
    ----------