@@ -82,8 +82,8 @@ class BaseFileLock(ABC, contextlib.ContextDecorator):
8282 def __new__ ( # noqa: PLR0913
8383 cls ,
8484 lock_file : str | os .PathLike [str ],
85- timeout : float = - 1 , # noqa: ARG003
86- mode : int = 0o644 , # noqa: ARG003
85+ timeout : float = - 1 ,
86+ mode : int = 0o644 ,
8787 thread_local : bool = True , # noqa: ARG003, FBT001, FBT002
8888 * ,
8989 is_singleton : bool = False ,
@@ -97,6 +97,9 @@ def __new__( # noqa: PLR0913
9797 if not instance :
9898 instance = super ().__new__ (cls )
9999 cls ._instances [str (lock_file )] = instance
100+ elif timeout != instance .timeout or mode != instance .mode :
101+ msg = "Singleton lock instances cannot be initialized with differing arguments"
102+ raise ValueError (msg )
100103
101104 return instance # type: ignore[return-value] # https://github.com/python/mypy/issues/15322
102105
@@ -174,6 +177,11 @@ def timeout(self, value: float | str) -> None:
174177 """
175178 self ._context .timeout = float (value )
176179
180+ @property
181+ def mode (self ) -> int :
182+ """:return: the file permissions for the lockfile"""
183+ return self ._context .mode
184+
177185 @abstractmethod
178186 def _acquire (self ) -> None :
179187 """If the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file."""
0 commit comments