|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +""" |
| 8 | +In the actual implementation of `filelock`, the type `BaseFileLock` is marked |
| 9 | +as abstract. And Pyre does not allow us to instantiate a variable of `Type[X]` |
| 10 | +when `X` is abstract because we cannot be sure that the type is valid to |
| 11 | +instantiate. |
| 12 | +
|
| 13 | +In reality, the `FileLock` type is always some concrete instantiatable type so |
| 14 | +it is okay to use; this stub makes Pyre happy by declaring BaseFileLock as not |
| 15 | +abstract. |
| 16 | +""" |
| 17 | + |
| 18 | +import types |
| 19 | +import typing as t |
| 20 | + |
| 21 | +class Timeout(TimeoutError): |
| 22 | + lock_file: str |
| 23 | + def __init__(self, lock_file: str) -> None: ... |
| 24 | + def __str__(self) -> str: ... |
| 25 | + |
| 26 | +class BaseFileLock: |
| 27 | + def __init__(self, lock_file: str, timeout: float = -1) -> None: ... |
| 28 | + @property |
| 29 | + def lock_file(self) -> str: ... |
| 30 | + @property |
| 31 | + def timeout(self) -> float: ... |
| 32 | + @timeout.setter |
| 33 | + def timeout(self, value: float) -> None: ... |
| 34 | + @property |
| 35 | + def is_locked(self) -> bool: ... |
| 36 | + def acquire( |
| 37 | + self, timeout: t.Optional[float] = None, poll_intervall: float = 0.05 |
| 38 | + ) -> t.Any: ... |
| 39 | + def release(self, force: bool = False) -> None: ... |
| 40 | + def __enter__(self) -> BaseFileLock: ... |
| 41 | + def __exit__( |
| 42 | + self, |
| 43 | + exc_type: t.Optional[type], |
| 44 | + exc_value: t.Optional[Exception], |
| 45 | + traceback: t.Optional[types.TracebackType], |
| 46 | + ) -> None: ... |
| 47 | + def __del__(self) -> None: ... |
| 48 | + |
| 49 | +class WindowsFileLock(BaseFileLock): ... |
| 50 | +class UnixFileLock(BaseFileLock): ... |
| 51 | +class SoftFileLock(BaseFileLock): ... |
| 52 | + |
| 53 | +FileLock: t.Type[BaseFileLock] |
0 commit comments