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
9a7e7740
Kaydet (Commit)
9a7e7740
authored
Şub 25, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add support for static and class methods.
üst
88470ec3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
+36
-3
xreload.py
Lib/xreload.py
+36
-3
No files found.
Lib/xreload.py
Dosyayı görüntüle @
9a7e7740
...
...
@@ -65,6 +65,7 @@ def xreload(mod):
for
name
in
newnames
-
oldnames
:
modns
[
name
]
=
tmpns
[
name
]
# Delete names that are no longer current
# XXX What to do about renamed objects?
for
name
in
oldnames
-
newnames
-
{
"__name__"
}:
del
modns
[
name
]
# Now update the rest in place
...
...
@@ -86,6 +87,9 @@ def _update(oldobj, newobj):
Returns:
either oldobj, updated in place, or newobj.
"""
if
oldobj
is
newobj
:
# Probably something imported
return
newobj
if
type
(
oldobj
)
is
not
type
(
newobj
):
# Cop-out: if the type changed, give up
return
newobj
...
...
@@ -98,11 +102,18 @@ def _update(oldobj, newobj):
return
_update_function
(
oldobj
,
newobj
)
if
isinstance
(
newobj
,
types
.
MethodType
):
return
_update_method
(
oldobj
,
newobj
)
# XXX Support class methods, static methods, other decorators
if
isinstance
(
newobj
,
classmethod
):
return
_update_classmethod
(
oldobj
,
newobj
)
if
isinstance
(
newobj
,
staticmethod
):
return
_update_staticmethod
(
oldobj
,
newobj
)
# XXX How to support decorators?
# Not something we recognize, just give up
return
newobj
# All of the following functions have the same signature as _update()
def
_update_function
(
oldfunc
,
newfunc
):
"""Update a function object."""
oldfunc
.
__doc__
=
newfunc
.
__doc__
...
...
@@ -116,7 +127,7 @@ def _update_function(oldfunc, newfunc):
def
_update_method
(
oldmeth
,
newmeth
):
"""Update a method object."""
# XXX What if im_func is not a function?
_update
_function
(
oldmeth
.
im_func
,
newmeth
.
im_func
)
_update
(
oldmeth
.
im_func
,
newmeth
.
im_func
)
return
oldmeth
...
...
@@ -132,5 +143,27 @@ def _update_class(oldclass, newclass):
for
name
in
oldnames
-
newnames
:
delattr
(
oldclass
,
name
)
for
name
in
oldnames
&
newnames
-
{
"__dict__"
,
"__doc__"
}:
setattr
(
oldclass
,
name
,
newdict
[
name
]
)
setattr
(
oldclass
,
name
,
_update
(
olddict
[
name
],
newdict
[
name
])
)
return
oldclass
def
_update_classmethod
(
oldcm
,
newcm
):
"""Update a classmethod update."""
# While we can't modify the classmethod object itself (it has no
# mutable attributes), we *can* extract the underlying function
# (by calling __get__(), which returns a method object) and update
# it in-place. We don't have the class available to pass to
# __get__() but any object except None will do.
_update
(
oldcm
.
__get__
(
0
),
newcm
.
__get__
(
0
))
return
newcm
def
_update_staticmethod
(
oldsm
,
newsm
):
"""Update a staticmethod update."""
# While we can't modify the staticmethod object itself (it has no
# mutable attributes), we *can* extract the underlying function
# (by calling __get__(), which returns it) and update it in-place.
# We don't have the class available to pass to __get__() but any
# object except None will do.
_update
(
oldsm
.
__get__
(
0
),
newsm
.
__get__
(
0
))
return
newsm
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