Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
bc8e81dc
Kaydet (Commit)
bc8e81dc
authored
Mar 17, 2012
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Section-off the source for better readability.
üst
dce583e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
functools.py
Lib/functools.py
+23
-0
No files found.
Lib/functools.py
Dosyayı görüntüle @
bc8e81dc
...
...
@@ -18,6 +18,11 @@ try:
except
:
from
_dummy_thread
import
allocate_lock
as
Lock
################################################################################
### update_wrapper() and wraps() decorator
################################################################################
# update_wrapper() and wraps() are tools to help write
# wrapper functions that can handle naive introspection
...
...
@@ -66,6 +71,11 @@ def wraps(wrapped,
return
partial
(
update_wrapper
,
wrapped
=
wrapped
,
assigned
=
assigned
,
updated
=
updated
)
################################################################################
### total_ordering class decorator
################################################################################
def
total_ordering
(
cls
):
"""Class decorator that fills in missing ordering methods"""
convert
=
{
...
...
@@ -94,6 +104,11 @@ def total_ordering(cls):
setattr
(
cls
,
opname
,
opfunc
)
return
cls
################################################################################
### cmp_to_key() function converter
################################################################################
def
cmp_to_key
(
mycmp
):
"""Convert a cmp= function into a key= function"""
class
K
(
object
):
...
...
@@ -120,6 +135,11 @@ try:
except
ImportError
:
pass
################################################################################
### LRU Cache function decorator
################################################################################
_CacheInfo
=
namedtuple
(
"CacheInfo"
,
[
"hits"
,
"misses"
,
"maxsize"
,
"currsize"
])
def
lru_cache
(
maxsize
=
100
,
typed
=
False
):
...
...
@@ -170,6 +190,7 @@ def lru_cache(maxsize=100, typed=False):
return
key
if
maxsize
is
None
:
@wraps
(
user_function
)
def
wrapper
(
*
args
,
**
kwds
):
# simple caching without ordering or size limit
...
...
@@ -183,7 +204,9 @@ def lru_cache(maxsize=100, typed=False):
cache
[
key
]
=
result
misses
+=
1
return
result
else
:
@wraps
(
user_function
)
def
wrapper
(
*
args
,
**
kwds
):
# size limited caching that tracks accesses by recency
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment