Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01c8d59

Browse files
committed
Add initial types to objects.util.py
1 parentecb12c2 commit01c8d59

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

‎git/objects/blob.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Blob(base.IndexObject):
2424
__slots__= ()
2525

2626
@property
27-
defmime_type(self)->Union[None,Tuple[Union[None,str],Union[None,str]]]:
27+
defmime_type(self)->Union[None,str,Tuple[Union[None,str],Union[None,str]]]:
2828
"""
2929
:return: String describing the mime type of this file (based on the filename)
3030
:note: Defaults to 'text/plain' in case the actual file type is unknown. """

‎git/objects/util.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
importcalendar
1818
fromdatetimeimportdatetime,timedelta,tzinfo
1919

20+
21+
fromtypingimportTYPE_CHECKING,Union
22+
23+
ifTYPE_CHECKING:
24+
from .commitimportCommit
25+
from .blobimportBlob
26+
from .tagimportTagObject
27+
from .treeimportTree
28+
2029
__all__= ('get_object_type_by_name','parse_date','parse_actor_and_date',
2130
'ProcessStreamAdapter','Traversable','altz_to_utctz_str','utctz_to_altz',
2231
'verify_utctz','Actor','tzoffset','utc')
@@ -26,7 +35,7 @@
2635
#{ Functions
2736

2837

29-
defmode_str_to_int(modestr):
38+
defmode_str_to_int(modestr:str)->int:
3039
"""
3140
:param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used
3241
:return:
@@ -41,7 +50,7 @@ def mode_str_to_int(modestr):
4150
returnmode
4251

4352

44-
defget_object_type_by_name(object_type_name):
53+
defget_object_type_by_name(object_type_name:str)->Union['Commit','TagObject','Tree','Blob']:
4554
"""
4655
:return: type suitable to handle the given object type name.
4756
Use the type to create new instances.
@@ -65,15 +74,15 @@ def get_object_type_by_name(object_type_name):
6574
raiseValueError("Cannot handle unknown object type: %s"%object_type_name)
6675

6776

68-
defutctz_to_altz(utctz):
77+
defutctz_to_altz(utctz:str)->int:
6978
"""we convert utctz to the timezone in seconds, it is the format time.altzone
7079
returns. Git stores it as UTC timezone which has the opposite sign as well,
7180
which explains the -1 * ( that was made explicit here )
7281
:param utctz: git utc timezone string, i.e. +0200"""
7382
return-1*int(float(utctz)/100*3600)
7483

7584

76-
defaltz_to_utctz_str(altz):
85+
defaltz_to_utctz_str(altz:int)->str:
7786
"""As above, but inverses the operation, returning a string that can be used
7887
in commit objects"""
7988
utci=-1*int((float(altz)/3600)*100)
@@ -83,7 +92,7 @@ def altz_to_utctz_str(altz):
8392
returnprefix+utcs
8493

8594

86-
defverify_utctz(offset):
95+
defverify_utctz(offset:str)->str:
8796
""":raise ValueError: if offset is incorrect
8897
:return: offset"""
8998
fmt_exc=ValueError("Invalid timezone offset format: %s"%offset)
@@ -101,6 +110,7 @@ def verify_utctz(offset):
101110

102111

103112
classtzoffset(tzinfo):
113+
104114
def__init__(self,secs_west_of_utc,name=None):
105115
self._offset=timedelta(seconds=-secs_west_of_utc)
106116
self._name=nameor'fixed'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp