FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/MutatingDescriptor.py at codeql-cli-2.11.3 · github/codeql · GitHub
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Issues
1k
Pull requests
468
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
MutatingDescriptor.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (29 loc) · 764 Bytes
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
MutatingDescriptor.py
Copy path
File metadata and controls
40 lines (29 loc) · 764 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#This is prone to strange side effects and race conditions.
class
MutatingDescriptor
(
object
):
def
__init__
(
self
,
func
):
self
.
my_func
=
func
def
__get__
(
self
,
obj
,
obj_type
):
#Modified state is visible to all instances of C that might call "show".
self
.
my_obj
=
obj
return
self
def
__call__
(
self
,
*
args
):
return
self
.
my_func
(
self
.
my_obj
,
*
args
)
def
show
(
obj
):
print
(
obj
)
class
C
(
object
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__str__
(
self
):
return
(
"C: "
+
str
(
self
.
value
))
show
=
MutatingDescriptor
(
show
)
c1
=
C
(
1
)
c1
.
show
()
c2
=
C
(
2
)
c2
.
show
()
c1_show
=
c1
.
show
c2
.
show
c1_show
()
#Outputs:
#C: 1
#C: 2
#C: 2
Back
|
FazBrowse Home
|
New Git URL