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

Method __getitem__

pygit2/index.py:89–104  ·  view source on GitHub ↗
(self, key: str | int | PathLike[str])

Source from the content-addressed store, hash-verified

87 return True
88
89 def __getitem__(self, key: str | int | PathLike[str]) -> 'IndexEntry':
90 centry = ffi.NULL
91 if isinstance(key, str) or hasattr(key, '__fspath__'):
92 centry = C.git_index_get_bypath(self._index, to_bytes(key), 0)
93 elif isinstance(key, int):
94 if key >= 0:
95 centry = C.git_index_get_byindex(self._index, key)
96 else:
97 raise ValueError(key)
98 else:
99 raise TypeError(f'Expected str or int, got {type(key)}')
100
101 if centry == ffi.NULL:
102 raise KeyError(key)
103
104 return IndexEntry._from_c(centry)
105
106 def __iter__(self):
107 return GenericIterator(self)

Callers

nothing calls this directly

Calls 2

to_bytesFunction · 0.85
_from_cMethod · 0.45

Tested by

no test coverage detected