MCPcopy Create free account
hub / github.com/libgit2/pygit2 / __init__

Method __init__

pygit2/utils.py:150–169  ·  view source on GitHub ↗
(self, lst: None | Sequence[str | os.PathLike[str]])

Source from the content-addressed store, hash-verified

148 __arr: 'ArrayC[char_pointer]'
149
150 def __init__(self, lst: None | Sequence[str | os.PathLike[str]]):
151 # Allow passing in None as lg2 typically considers them the same as empty
152 if lst is None:
153 self.__array = ffi.NULL
154 return
155
156 if not isinstance(lst, (list, tuple)):
157 raise TypeError('Value must be a list')
158
159 strings: list[None | 'ArrayC[char]'] = [None] * len(lst)
160 for i in range(len(lst)):
161 li = lst[i]
162 if not isinstance(li, str) and not hasattr(li, '__fspath__'):
163 raise TypeError('Value must be a string or PathLike object')
164
165 strings[i] = ffi.new('char []', to_bytes(li))
166
167 self.__arr = ffi.new('char *[]', strings)
168 self.__strings = strings
169 self.__array = ffi.new('git_strarray *', [self.__arr, len(strings)]) # type: ignore[call-overload]
170
171 def __enter__(self) -> 'StrArray':
172 return self

Callers

nothing calls this directly

Calls 1

to_bytesFunction · 0.85

Tested by

no test coverage detected