Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 180639b

Browse files
authored
Merge pull request matplotlib#10534 from anntzer/getrealpathandstat
Modernize cbook.get_realpath_and_stat.
2 parents fbc6983 + d7bdc0f commit 180639b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Deprecations
22
````````````
3-
The following functions are deprecated:
4-
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead)
5-
- ``mathtext.unichr_safe`` (use ``chr`` instead)
3+
The following functions and classes are deprecated:
4+
5+
- ``cbook.GetRealpathAndStat`` (which is only a helper for
6+
``get_realpath_and_stat``),
7+
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead),
8+
- ``mathtext.unichr_safe`` (use ``chr`` instead),

lib/matplotlib/cbook/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ def mkdirs(newdir, mode=0o777):
864864
raise
865865

866866

867+
@deprecated('3.0')
867868
class GetRealpathAndStat(object):
868869
def __init__(self):
869870
self._cache = {}
@@ -882,7 +883,12 @@ def __call__(self, path):
882883
return result
883884

884885

885-
get_realpath_and_stat = GetRealpathAndStat()
886+
@functools.lru_cache()
887+
def get_realpath_and_stat(path):
888+
realpath = os.path.realpath(path)
889+
stat = os.stat(realpath)
890+
stat_key = (stat.st_ino, stat.st_dev)
891+
return realpath, stat_key
886892

887893

888894
@deprecated('2.1')

0 commit comments

Comments
 (0)