Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
211a5ef2
Commit
211a5ef2
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
generic __copy__ fixes
parent
4f63567e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/coding/structures/dictionaries.py
+12
-3
12 additions, 3 deletions
satella/coding/structures/dictionaries.py
with
12 additions
and
3 deletions
satella/coding/structures/dictionaries.py
+
12
−
3
View file @
211a5ef2
...
@@ -276,7 +276,7 @@ class TwoWayDictionary(collections.abc.MutableMapping, tp.Generic[K, V]):
...
@@ -276,7 +276,7 @@ class TwoWayDictionary(collections.abc.MutableMapping, tp.Generic[K, V]):
return
self
.
_reverse
return
self
.
_reverse
class
DirtyDict
(
collections
.
UserDict
):
class
DirtyDict
(
collections
.
UserDict
,
tp
.
Generic
[
K
,
V
]
):
"""
"""
A dictionary that has also a flag called .dirty that sets to True if the dictionary has been
A dictionary that has also a flag called .dirty that sets to True if the dictionary has been
changed since that flag was last cleared.
changed since that flag was last cleared.
...
@@ -289,6 +289,11 @@ class DirtyDict(collections.UserDict):
...
@@ -289,6 +289,11 @@ class DirtyDict(collections.UserDict):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
dirty
=
False
self
.
dirty
=
False
def
__copy__
(
self
):
dd
=
DirtyDict
(
self
.
data
.
copy
())
dd
.
dirty
=
self
.
dirty
return
dd
def
__setitem__
(
self
,
key
:
K
,
value
:
V
)
->
None
:
def
__setitem__
(
self
,
key
:
K
,
value
:
V
)
->
None
:
if
key
in
self
:
if
key
in
self
:
if
self
[
key
]
==
value
:
if
self
[
key
]
==
value
:
...
@@ -305,7 +310,11 @@ class DirtyDict(collections.UserDict):
...
@@ -305,7 +310,11 @@ class DirtyDict(collections.UserDict):
self
.
dirty
=
False
self
.
dirty
=
False
def
copy_and_clear_dirty
(
self
)
->
tp
.
Dict
[
K
,
V
]:
def
copy_and_clear_dirty
(
self
)
->
tp
.
Dict
[
K
,
V
]:
"""
Returns a copy of self and clears the dirty flag
"""
"""
a
=
self
.
copy
()
Returns a copy of self and clears the dirty flag
:return: a plain, normal Python dictionary is returned
"""
a
=
self
.
data
.
copy
()
self
.
dirty
=
False
self
.
dirty
=
False
return
a
return
a
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment