MCPcopy Index your code
hub / github.com/python/cpython / _follow

Method _follow

Lib/importlib/resources/readers.py:107–123  ·  view source on GitHub ↗

Construct a MultiplexedPath if needed. If children contains a sole element, return it. Otherwise, return a MultiplexedPath of the items. Unless one of the items is not a Directory, then return the first.

(cls, children)

Source from the content-addressed store, hash-verified

105
106 @classmethod
107 def _follow(cls, children):
108 """
109 Construct a MultiplexedPath if needed.
110
111 If children contains a sole element, return it.
112 Otherwise, return a MultiplexedPath of the items.
113 Unless one of the items is not a Directory, then return the first.
114 """
115 subdirs, one_dir, one_file = itertools.tee(children, 3)
116
117 try:
118 return only(one_dir)
119 except ValueError:
120 try:
121 return cls(*subdirs)
122 except NotADirectoryError:
123 return next(one_file)
124
125 def open(self, *args, **kwargs):
126 raise FileNotFoundError(f'{self} is not a file')

Callers

nothing calls this directly

Calls 3

onlyFunction · 0.85
teeMethod · 0.80
clsClass · 0.50

Tested by

no test coverage detected