Repository: matplotlib/matplotlib
File: lib/matplotlib/contour.py (Python)

Code before:
        i1 = over[0] + 1 if len(over) else len(lev)
        if self.extend in ('min', 'both'):
            i0 += 1
        if self.extend in ('max', 'both'):
            i1 -= 1

        if i1 - i0 < 3:
            i0, i1 = 0, len(lev)

        return lev[i0:i1]

    def _process_contour_level_args(self, args, z_dtype):
        """
        Determine the contour levels and store in self.levels.
        """
        levels_arg = self.levels
        if levels_arg is None:
            if args:
                # Set if levels manually provided
                levels_arg = args[0]
            elif np.issubdtype(z_dtype, bool):
                # Set default values for bool data types
                if self.filled:
                    levels_arg = [0, .5, 1]
                else:
                    levels_arg = [.5]

        if isinstance(levels_arg, (Integral, None)):
            self.levels = self._autolev(levels_arg)
        else:
            self.levels = np.asarray(levels_arg, np.float64)

        if self.filled and len(self.levels) < 2:
            raise ValueError("Filled contours require at least 2 levels.")
        if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
            raise ValueError("Contour levels must be increasing")

    def _process_levels(self):
        """
        Assign values to :attr:`layers` based on :attr:`levels`,
        adding extended layers as needed if contours are filled.

        For line contours, layers simply coincide with levels;
        a line is a thin layer.  No extended levels are needed
        with line contours.
        """
        # Make a private _levels to include extended regions; we
        # want to leave the original levels attribute unchanged.
        # (Colorbar needs this even for line contours.)
        self._levels = list(self.levels)


Review comment (suggestion):
```suggestion
                levels_arg = [0, .5, 1] if self.filled else [.5]
```
looks more concise

Code after:
        over = np.nonzero(lev > self.zmax)[0]
        i1 = over[0] + 1 if len(over) else len(lev)
        if self.extend in ('min', 'both'):
            i0 += 1
        if self.extend in ('max', 'both'):
            i1 -= 1

        if i1 - i0 < 3:
            i0, i1 = 0, len(lev)

        return lev[i0:i1]

    def _process_contour_level_args(self, args, z_dtype):
        """
        Determine the contour levels and store in self.levels.
        """
        levels_arg = self.levels
        if levels_arg is None:
            if args:
                # Set if levels manually provided
                levels_arg = args[0]
            elif np.issubdtype(z_dtype, bool):
                # Set default values for bool data types
                levels_arg = [0, .5, 1] if self.filled else [.5]

        if isinstance(levels_arg, Integral) or levels_arg is None:
            self._ensure_locator_exists(levels_arg)
            self.levels = self._autolev()
        else:
            self.levels = np.asarray(levels_arg, np.float64)

        if self.filled and len(self.levels) < 2:
            raise ValueError("Filled contours require at least 2 levels.")
        if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
            raise ValueError("Contour levels must be increasing")

    def _process_levels(self):
        """
        Assign values to :attr:`layers` based on :attr:`levels`,
        adding extended layers as needed if contours are filled.

        For line contours, layers simply coincide with levels;
        a line is a thin layer.  No extended levels are needed
        with line contours.
        """
        # Make a private _levels to include extended regions; we
        # want to leave the original levels attribute unchanged.
        # (Colorbar needs this even for line contours.)
        self._levels = list(self.levels)

        if self.logscale: