timestamp: add type information to the module
authorRaphaël Gomès <rgomes@octobus.net>
Wed, 16 Oct 2024 18:40:59 +0200
changeset 52056 7ea1cb46b590
parent 52055 0529e1a468dd
child 52057 572d80e51094
timestamp: add type information to the module This is easy to do and helps both Pytype and developpers understand what objects they are dealing with.
mercurial/dirstateutils/timestamp.py
--- a/mercurial/dirstateutils/timestamp.py	Wed Oct 16 17:19:38 2024 +0200
+++ b/mercurial/dirstateutils/timestamp.py	Wed Oct 16 18:40:59 2024 +0200
@@ -8,6 +8,8 @@
 import functools
 import os
 import stat
+import time
+from typing import Optional, Tuple
 
 from .. import error
 
@@ -49,7 +51,7 @@
         )
 
 
-def get_fs_now(vfs):
+def get_fs_now(vfs) -> Optional[timestamp]:
     """return a timestamp for "now" in the current vfs
 
     This will raise an exception if no temporary files could be created.
@@ -62,14 +64,14 @@
         vfs.unlink(tmpname)
 
 
-def zero():
+def zero() -> timestamp:
     """
     Returns the `timestamp` at the Unix epoch.
     """
     return tuple.__new__(timestamp, (0, 0))
 
 
-def mtime_of(stat_result):
+def mtime_of(stat_result: os.stat_result) -> timestamp:
     """
     Takes an `os.stat_result`-like object and returns a `timestamp` object
     for its modification time.
@@ -95,7 +97,9 @@
     return timestamp((secs, subsec_nanos, False))
 
 
-def reliable_mtime_of(stat_result, present_mtime):
+def reliable_mtime_of(
+    stat_result: os.stat_result, present_mtime: timestamp
+) -> Optional[timestamp]:
     """Same as `mtime_of`, but return `None` or a `Timestamp` with
     `second_ambiguous` set if the date might be ambiguous.