Repository: Lightning-AI/pytorch-lightning
File: pytorch_lightning/callbacks/model_checkpoint.py (Python)

Code before:

    def __init_ckpt_dir(self, filepath, dirpath, filename, save_top_k):
        if filepath:
            if (dirpath or filename):
                raise MisconfigurationException(
                    f'You have set all three path/name inputs which are not feasible.'
                    f' You have to choose either filepath={filepath} OR dirpath={dirpath}'
                    f' and filename={filename} configuration.'
                )

            rank_zero_warn(
                'Argument `filepath` is deprecated in v1.0 and will be removed in v1.2.'
                ' Please use `dirpath` and `filename` instead.', DeprecationWarning
            )

            _fs = get_filesystem(filepath)

            if _fs.isdir(filepath):
                dirpath, filename = filepath, None
            else:
                if _fs.protocol == 'file':
                    filepath = os.path.realpath(filepath)
                dirpath, filename = os.path.split(filepath)

        dirpath = str(dirpath) if dirpath else dirpath
        self._fs = get_filesystem(dirpath or '')

        if (
            save_top_k is not None
            and save_top_k > 0
            and dirpath is not None
            and self._fs.isdir(dirpath)
            and len(self._fs.ls(dirpath)) > 0
        ):
            rank_zero_warn(
                f"Checkpoint directory {dirpath} exists and is not empty. With save_top_k={save_top_k},"
                " all files in this directory will be deleted when a checkpoint is saved!"
            )

        if dirpath and self._fs.protocol == 'file':
            dirpath = os.path.realpath(dirpath)

        self.dirpath = dirpath or None
        self.filename = filename or None

    def __init_monitor_mode(self, monitor, mode):
        torch_inf = torch.tensor(np.Inf)
        mode_dict = {
            "min": (torch_inf, "min"),
            "max": (-torch_inf, "max"),
            "auto": (-torch_inf, "max")

Review comment (suggestion):
```suggestion
        self._fs = get_filesystem(str(dirpath) if dirpath else '')
```

Code after:
                )

    def __init_ckpt_dir(self, filepath, dirpath, filename, save_top_k):
        if filepath:
            if (dirpath or filename):
                raise MisconfigurationException(
                    'You have set all three path/name inputs which are not feasible.'
                    f' You have to choose either filepath={filepath} OR dirpath={dirpath}'
                    f' and filename={filename} configuration.'
                )

            rank_zero_warn(
                'Argument `filepath` is deprecated in v1.0 and will be removed in v1.2.'
                ' Please use `dirpath` and `filename` instead.', DeprecationWarning
            )

            _fs = get_filesystem(filepath)

            if _fs.isdir(filepath):
                dirpath, filename = filepath, None
            else:
                if _fs.protocol == 'file':
                    filepath = os.path.realpath(filepath)
                dirpath, filename = os.path.split(filepath)

        self._fs = get_filesystem(str(dirpath) if dirpath else '')

        if (
            save_top_k is not None
            and save_top_k > 0
            and dirpath is not None
            and self._fs.isdir(dirpath)
            and len(self._fs.ls(dirpath)) > 0
        ):
            rank_zero_warn(
                f"Checkpoint directory {dirpath} exists and is not empty. With save_top_k={save_top_k},"
                " all files in this directory will be deleted when a checkpoint is saved!"
            )

        if dirpath and self._fs.protocol == 'file':
            dirpath = os.path.realpath(dirpath)

        self.dirpath = dirpath or None
        self.filename = filename or None

    def __init_monitor_mode(self, monitor, mode):
        torch_inf = torch.tensor(np.Inf)
        mode_dict = {
            "min": (torch_inf, "min"),
            "max": (-torch_inf, "max"),
            "auto": (-torch_inf, "max")