Repository: matplotlib/matplotlib
File: lib/matplotlib/axes/_axes.py (Python)

Code before:

        See Also
        --------
        violinplot :
            Draw a violin plot from data instead of pre-computed statistics.
        .cbook.violin_stats:
            Calculate a *vpstats* dictionary from data, suitable for passing to violin.
        """

        # Statistical quantities to be plotted on the violins
        means = []
        mins = []
        maxes = []
        medians = []
        quantiles = []

        qlens = []  # Number of quantiles in each dataset.

        artists = {}  # Collections to be returned

        N = len(vpstats)
        if N == 0:
            # Return empty artists dict for empty input
            return {key: [] for key in [
                'bodies', 'cmeans', 'cmins', 'cmaxes', 'cbars',
                'cmedians', 'cquantiles']}
        datashape_message = ("List of violinplot statistics and `{0}` "
                             "values must have the same length")

        # vert and orientation parameters are linked until vert's
        # deprecation period expires. If both are selected,
        # vert takes precedence.
        if vert is not None:
            _api.warn_deprecated(
                "3.11",
                name="vert: bool",
                alternative="orientation: {'vertical', 'horizontal'}",
            )
            orientation = 'vertical' if vert else 'horizontal'
        _api.check_in_list(['horizontal', 'vertical'], orientation=orientation)

        # Validate positions
        if positions is None:
            positions = range(1, N + 1)
        elif len(positions) != N:
            raise ValueError(datashape_message.format("positions"))
        pre_conversion_widths = widths
        # Validate widths
        if np.isscalar(widths):
            widths = [widths] * N
        elif len(widths) != N:

Review comment (suggestion):
This is not correct. So far:
```python
In [3]: ax.violin([])
Out[3]: 
{'bodies': [],
 'cmaxes': <matplotlib.collections.LineCollection at 0x787bf23cb080>,
 'cmins': <matplotlib.collections.LineCollection at 0x787be8142ea0>,
 'cbars': <matplotlib.collections.LineCollection at 0x787be821f9e0>}
```
While early returns are usually good, I wouldn't do it in this case as you'd have to exactly figure out how to construct the complex return type. Just let it fall through as before


Code after:

        See Also
        --------
        violinplot :
            Draw a violin plot from data instead of pre-computed statistics.
        .cbook.violin_stats:
            Calculate a *vpstats* dictionary from data, suitable for passing to violin.
        """

        # Statistical quantities to be plotted on the violins
        means = []
        mins = []
        maxes = []
        medians = []
        quantiles = []

        qlens = []  # Number of quantiles in each dataset.

        artists = {}  # Collections to be returned

        N = len(vpstats)
        datashape_message = ("List of violinplot statistics and `{0}` "
                             "values must have the same length")

        # vert and orientation parameters are linked until vert's
        # deprecation period expires. If both are selected,
        # vert takes precedence.
        if vert is not None:
            _api.warn_deprecated(
                "3.11",
                name="vert: bool",
                alternative="orientation: {'vertical', 'horizontal'}",
            )
            orientation = 'vertical' if vert else 'horizontal'
        _api.check_in_list(['horizontal', 'vertical'], orientation=orientation)

        # Validate positions
        if positions is None:
            positions = range(1, N + 1)
        elif len(positions) != N:
            raise ValueError(datashape_message.format("positions"))
        # Validate widths
        if np.isscalar(widths):
            widths = [widths] * N
        elif len(widths) != N:
            raise ValueError(datashape_message.format("widths"))

        # For usability / better error message:
        # Validate that datetime-like positions have timedelta-like widths.
        # Checking only the first element is good enough for standard misuse cases
        if N > 0:  # No need to validate if there is no data