def _repr_pen_commands(commands):
    """
    >>> print(_repr_pen_commands([
    ...     ('moveTo', tuple(), {}),
    ...     ('lineTo', ((1.0, 0.1),), {}),
    ...     ('curveTo', ((1.0, 0.1), (2.0, 0.2), (3.0, 0.3)), {})
    ... ]))
    pen.moveTo()
    pen.lineTo((1, 0.1))
    pen.curveTo((1, 0.1), (2, 0.2), (3, 0.3))

    >>> print(_repr_pen_commands([
    ...     ('beginPath', tuple(), {}),
    ...     ('addPoint', ((1.0, 0.1),),
    ...      {"segmentType":"line", "smooth":True, "name":"test", "z":1}),
    ... ]))
    pen.beginPath()
    pen.addPoint((1, 0.1), name='test', segmentType='line', smooth=True, z=1)

    >>> print(_repr_pen_commands([
    ...    ('addComponent', ('A', (1, 0, 0, 1, 0, 0)), {})
    ... ]))
    pen.addComponent('A', (1, 0, 0, 1, 0, 0))
    """
    s = []
    for cmd, args, kwargs in commands:
        if args:
            if isinstance(args[0], tuple):
                # cast float to int if there're no digits after decimal point
                args = [tuple((int(v) if int(v) == v else v) for v in pt)
                        for pt in args]
            args = ", ".join(repr(a) for a in args)
        if kwargs:
            kwargs = ", ".join("%s=%r" % (k, v)
                               for k, v in sorted(kwargs.items()))
        if args and kwargs:
            s.append("pen.%s(%s, %s)" % (cmd, args, kwargs))
        elif args:
            s.append("pen.%s(%s)" % (cmd, args))
        elif kwargs:
            s.append("pen.%s(%s)" % (cmd, kwargs))
        else:
            s.append("pen.%s()" % cmd)
    return "\n".join(s)