Skip to content

Use cached_property for pathlib.Path instead of cache data in property #138655

@Zheaoli

Description

@Zheaoli

Feature or enhancement

Proposal:

We can use

    @cached_property
    def _str_normcase(self):
        # String with normalized case, for hashing and equality checks
        if self.parser is posixpath:
            return str(self)
        else:
            return str(self).lower()

instead of

    @property
    def _str_normcase(self):
        # String with normalized case, for hashing and equality checks
        try:
            return self._str_normcase_cached
        except AttributeError:
            if self.parser is posixpath:
                self._str_normcase_cached = str(self)
            else:
                self._str_normcase_cached = str(self).lower()
            return self._str_normcase_cached

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions