Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 52877:9a8815128679
typing: add type hints to the `mercurial.util.transactional` class
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 08 Feb 2025 00:14:20 -0500 |
parents | 7a6fc0e2a89a |
children | 7ca9c05ec335 |
comparison
equal
deleted
inserted
replaced
52876:7a6fc0e2a89a | 52877:9a8815128679 |
---|---|
1426 | 1426 |
1427 class transactional(abc.ABC): | 1427 class transactional(abc.ABC): |
1428 """Base class for making a transactional type into a context manager.""" | 1428 """Base class for making a transactional type into a context manager.""" |
1429 | 1429 |
1430 @abc.abstractmethod | 1430 @abc.abstractmethod |
1431 def close(self): | 1431 def close(self) -> None: |
1432 """Successfully closes the transaction.""" | 1432 """Successfully closes the transaction.""" |
1433 | 1433 |
1434 @abc.abstractmethod | 1434 @abc.abstractmethod |
1435 def release(self): | 1435 def release(self) -> None: |
1436 """Marks the end of the transaction. | 1436 """Marks the end of the transaction. |
1437 | 1437 |
1438 If the transaction has not been closed, it will be aborted. | 1438 If the transaction has not been closed, it will be aborted. |
1439 """ | 1439 """ |
1440 | 1440 |
1441 def __enter__(self): | 1441 def __enter__(self) -> Self: |
1442 return self | 1442 return self |
1443 | 1443 |
1444 def __exit__(self, exc_type, exc_val, exc_tb): | 1444 def __exit__(self, exc_type, exc_val, exc_tb) -> None: |
1445 try: | 1445 try: |
1446 if exc_type is None: | 1446 if exc_type is None: |
1447 self.close() | 1447 self.close() |
1448 finally: | 1448 finally: |
1449 self.release() | 1449 self.release() |