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

Commitfd8537b

Browse files
authored
Merge pull request#523 from yarikoptic/enh-wraps
RF: use @functools.wraps within decorators instead of manual __name__ reassignment
2 parentsdf5c1cb +51f4a14 commitfd8537b

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

‎git/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
importabc
1818
importos
1919

20+
fromfunctoolsimportwraps
21+
2022
fromgit.odictimportOrderedDict
2123
fromgit.utilimportLockFile
2224
fromgit.compatimport (
@@ -67,11 +69,11 @@ def __new__(metacls, name, bases, clsdict):
6769
defneeds_values(func):
6870
"""Returns method assuring we read values (on demand) before we try to access them"""
6971

72+
@wraps(func)
7073
defassure_data_present(self,*args,**kwargs):
7174
self.read()
7275
returnfunc(self,*args,**kwargs)
7376
# END wrapper method
74-
assure_data_present.__name__=func.__name__
7577
returnassure_data_present
7678

7779

‎git/index/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
importstruct
33
importtempfile
44
importos
5+
6+
fromfunctoolsimportwraps
7+
58
fromgit.compatimportis_win
69

710
__all__= ('TemporaryFileSwap','post_clear_cache','default_index','git_working_dir')
@@ -48,13 +51,13 @@ def post_clear_cache(func):
4851
natively which in fact is possible, but probably not feasible performance wise.
4952
"""
5053

54+
@wraps(func)
5155
defpost_clear_cache_if_not_raised(self,*args,**kwargs):
5256
rval=func(self,*args,**kwargs)
5357
self._delete_entries_cache()
5458
returnrval
55-
5659
# END wrapper method
57-
post_clear_cache_if_not_raised.__name__=func.__name__
60+
5861
returnpost_clear_cache_if_not_raised
5962

6063

@@ -63,21 +66,22 @@ def default_index(func):
6366
repository index. This is as we rely on git commands that operate
6467
on that index only. """
6568

69+
@wraps(func)
6670
defcheck_default_index(self,*args,**kwargs):
6771
ifself._file_path!=self._index_path():
6872
raiseAssertionError(
6973
"Cannot call %r on indices that do not represent the default git index"%func.__name__)
7074
returnfunc(self,*args,**kwargs)
7175
# END wrpaper method
7276

73-
check_default_index.__name__=func.__name__
7477
returncheck_default_index
7578

7679

7780
defgit_working_dir(func):
7881
"""Decorator which changes the current working dir to the one of the git
7982
repository in order to assure relative paths are handled correctly"""
8083

84+
@wraps(func)
8185
defset_git_working_dir(self,*args,**kwargs):
8286
cur_wd=os.getcwd()
8387
os.chdir(self.repo.working_tree_dir)
@@ -88,7 +92,6 @@ def set_git_working_dir(self, *args, **kwargs):
8892
# END handle working dir
8993
# END wrapper
9094

91-
set_git_working_dir.__name__=func.__name__
9295
returnset_git_working_dir
9396

9497
#} END decorators

‎git/test/lib/helper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
importio
1313
importlogging
1414

15+
fromfunctoolsimportwraps
16+
1517
fromgitimportRepo,Remote,GitCommandError,Git
1618
fromgit.utilimportrmtree
1719
fromgit.compatimportstring_types,is_win
@@ -86,6 +88,7 @@ def with_rw_directory(func):
8688
"""Create a temporary directory which can be written to, remove it if the
8789
test succeeds, but leave it otherwise to aid additional debugging"""
8890

91+
@wraps(func)
8992
defwrapper(self):
9093
path=tempfile.mktemp(prefix=func.__name__)
9194
os.mkdir(path)
@@ -122,6 +125,7 @@ def with_rw_repo(working_tree_ref, bare=False):
122125
assertisinstance(working_tree_ref,string_types),"Decorator requires ref name for working tree checkout"
123126

124127
defargument_passer(func):
128+
@wraps(func)
125129
defrepo_creator(self):
126130
prefix='non_'
127131
ifbare:
@@ -155,7 +159,6 @@ def repo_creator(self):
155159
# END rm test repo if possible
156160
# END cleanup
157161
# END rw repo creator
158-
repo_creator.__name__=func.__name__
159162
returnrepo_creator
160163
# END argument passer
161164
returnargument_passer
@@ -211,6 +214,7 @@ def case(self, rw_repo, rw_remote_repo)
211214

212215
defargument_passer(func):
213216

217+
@wraps(func)
214218
defremote_repo_creator(self):
215219
remote_repo_dir=_mktemp("remote_repo_%s"%func.__name__)
216220
repo_dir=_mktemp("remote_clone_non_bare_repo")
@@ -319,10 +323,9 @@ def remote_repo_creator(self):
319323
gd.proc.wait()
320324
# END cleanup
321325
# END bare repo creator
322-
remote_repo_creator.__name__=func.__name__
323326
returnremote_repo_creator
324327
# END remote repo creator
325-
# END argumentparsser
328+
# END argumentparser
326329

327330
returnargument_passer
328331

‎git/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
importstat
1515
importtime
1616

17+
fromfunctoolsimportwraps
18+
1719
fromgit.compatimportis_win
1820
fromgitdb.utilimport (# NOQA
1921
make_sha,
@@ -50,13 +52,13 @@ def unbare_repo(func):
5052
"""Methods with this decorator raise InvalidGitRepositoryError if they
5153
encounter a bare repository"""
5254

55+
@wraps(func)
5356
defwrapper(self,*args,**kwargs):
5457
ifself.repo.bare:
5558
raiseInvalidGitRepositoryError("Method '%s' cannot operate on bare repositories"%func.__name__)
5659
# END bare method
5760
returnfunc(self,*args,**kwargs)
5861
# END wrapper
59-
wrapper.__name__=func.__name__
6062
returnwrapper
6163

6264

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp