2727Settings mapping.
2828"""
2929
30- from ssl import get_default_verify_paths
30+ from ssl import DefaultVerifyPaths , get_default_verify_paths
31+ from typing import overload
3132
3233import pygit2 .enums
3334
3435from ._pygit2 import option
35- from .enums import Option
36+ from .enums import ConfigLevel , Option
3637from .errors import GitError
3738
3839
3940class SearchPathList :
40- def __getitem__ (self , key ) :
41+ def __getitem__ (self , key : ConfigLevel ) -> str :
4142 return option (Option .GET_SEARCH_PATH , key )
4243
43- def __setitem__ (self , key , value ) :
44+ def __setitem__ (self , key : ConfigLevel , value : str ) -> None :
4445 option (Option .SET_SEARCH_PATH , key , value )
4546
4647
@@ -50,12 +51,15 @@ class Settings:
5051 __slots__ = '_default_tls_verify_paths' , '_ssl_cert_dir' , '_ssl_cert_file'
5152
5253 _search_path = SearchPathList ()
54+ _default_tls_verify_paths : DefaultVerifyPaths | None
55+ _ssl_cert_file : str | bytes | None
56+ _ssl_cert_dir : str | bytes | None
5357
54- def __init__ (self ):
58+ def __init__ (self ) -> None :
5559 """Initialize global pygit2 and libgit2 settings."""
5660 self ._initialize_tls_certificate_locations ()
5761
58- def _initialize_tls_certificate_locations (self ):
62+ def _initialize_tls_certificate_locations (self ) -> None :
5963 """Set up initial TLS file and directory lookup locations."""
6064 self ._default_tls_verify_paths = get_default_verify_paths ()
6165 try :
@@ -72,7 +76,7 @@ def _initialize_tls_certificate_locations(self):
7276 self ._ssl_cert_dir = None
7377
7478 @property
75- def search_path (self ):
79+ def search_path (self ) -> SearchPathList :
7680 """Configuration file search path.
7781
7882 This behaves like an array whose indices correspond to ConfigLevel values.
@@ -81,35 +85,35 @@ def search_path(self):
8185 return self ._search_path
8286
8387 @property
84- def mwindow_size (self ):
88+ def mwindow_size (self ) -> int :
8589 """Get or set the maximum mmap window size"""
8690 return option (Option .GET_MWINDOW_SIZE )
8791
8892 @mwindow_size .setter
89- def mwindow_size (self , value ) :
93+ def mwindow_size (self , value : int ) -> None :
9094 option (Option .SET_MWINDOW_SIZE , value )
9195
9296 @property
93- def mwindow_mapped_limit (self ):
97+ def mwindow_mapped_limit (self ) -> int :
9498 """
9599 Get or set the maximum memory that will be mapped in total by the
96100 library
97101 """
98102 return option (Option .GET_MWINDOW_MAPPED_LIMIT )
99103
100104 @mwindow_mapped_limit .setter
101- def mwindow_mapped_limit (self , value ) :
105+ def mwindow_mapped_limit (self , value : int ) -> None :
102106 option (Option .SET_MWINDOW_MAPPED_LIMIT , value )
103107
104108 @property
105- def cached_memory (self ):
109+ def cached_memory (self ) -> tuple [ int , int ] :
106110 """
107111 Get the current bytes in cache and the maximum that would be
108112 allowed in the cache.
109113 """
110114 return option (Option .GET_CACHED_MEMORY )
111115
112- def enable_caching (self , value = True ):
116+ def enable_caching (self , value : bool = True ) -> None :
113117 """
114118 Enable or disable caching completely.
115119
@@ -119,15 +123,15 @@ def enable_caching(self, value=True):
119123 """
120124 return option (Option .ENABLE_CACHING , value )
121125
122- def disable_pack_keep_file_checks (self , value = True ):
126+ def disable_pack_keep_file_checks (self , value : bool = True ) -> None :
123127 """
124128 This will cause .keep file existence checks to be skipped when
125129 accessing packfiles, which can help performance with remote
126130 filesystems.
127131 """
128132 return option (Option .DISABLE_PACK_KEEP_FILE_CHECKS , value )
129133
130- def cache_max_size (self , value ) :
134+ def cache_max_size (self , value : int ) -> None :
131135 """
132136 Set the maximum total data size that will be cached in memory
133137 across all repositories before libgit2 starts evicting objects
@@ -137,7 +141,9 @@ def cache_max_size(self, value):
137141 """
138142 return option (Option .SET_CACHE_MAX_SIZE , value )
139143
140- def cache_object_limit (self , object_type : pygit2 .enums .ObjectType , value ):
144+ def cache_object_limit (
145+ self , object_type : pygit2 .enums .ObjectType , value : int
146+ ) -> None :
141147 """
142148 Set the maximum data size for the given type of object to be
143149 considered eligible for caching in memory. Setting to value to
@@ -148,36 +154,46 @@ def cache_object_limit(self, object_type: pygit2.enums.ObjectType, value):
148154 return option (Option .SET_CACHE_OBJECT_LIMIT , object_type , value )
149155
150156 @property
151- def ssl_cert_file (self ):
157+ def ssl_cert_file (self ) -> str | bytes | None :
152158 """TLS certificate file path."""
153159 return self ._ssl_cert_file
154160
155161 @ssl_cert_file .setter
156- def ssl_cert_file (self , value ) :
162+ def ssl_cert_file (self , value : str | bytes ) -> None :
157163 """Set the TLS cert file path."""
158164 self .set_ssl_cert_locations (value , self ._ssl_cert_dir )
159165
160166 @ssl_cert_file .deleter
161- def ssl_cert_file (self ):
167+ def ssl_cert_file (self ) -> None :
162168 """Reset the TLS cert file path."""
163- self .ssl_cert_file = self ._default_tls_verify_paths .cafile
169+ self .ssl_cert_file = self ._default_tls_verify_paths .cafile # type: ignore[union-attr]
164170
165171 @property
166- def ssl_cert_dir (self ):
172+ def ssl_cert_dir (self ) -> str | bytes | None :
167173 """TLS certificates lookup directory path."""
168174 return self ._ssl_cert_dir
169175
170176 @ssl_cert_dir .setter
171- def ssl_cert_dir (self , value ) :
177+ def ssl_cert_dir (self , value : str | bytes ) -> None :
172178 """Set the TLS certificate lookup folder."""
173179 self .set_ssl_cert_locations (self ._ssl_cert_file , value )
174180
175181 @ssl_cert_dir .deleter
176- def ssl_cert_dir (self ):
182+ def ssl_cert_dir (self ) -> None :
177183 """Reset the TLS certificate lookup folder."""
178- self .ssl_cert_dir = self ._default_tls_verify_paths .capath
179-
180- def set_ssl_cert_locations (self , cert_file , cert_dir ):
184+ self .ssl_cert_dir = self ._default_tls_verify_paths .capath # type: ignore[union-attr]
185+
186+ @overload
187+ def set_ssl_cert_locations (
188+ self , cert_file : str | bytes | None , cert_dir : str | bytes
189+ ) -> None : ...
190+ @overload
191+ def set_ssl_cert_locations (
192+ self , cert_file : str | bytes , cert_dir : str | bytes | None
193+ ) -> None : ...
194+ def set_ssl_cert_locations (
195+ self , cert_file : str | bytes | None , cert_dir : str | bytes | None
196+ ) -> None :
181197 """
182198 Set the SSL certificate-authority locations.
183199
0 commit comments