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
a7bd1227
Commit
a7bd1227
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
warnings for some use cases of Closeable
parent
53711ad2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/coding/misc.py
+12
-3
12 additions, 3 deletions
satella/coding/misc.py
with
15 additions
and
4 deletions
CHANGELOG.md
+
2
−
0
View file @
a7bd1227
# v2.17.4
*
warnings for some use cases of Closeable
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
a7bd1227
__version__
=
'
2.17.4a
1
'
__version__
=
'
2.17.4a
2
'
This diff is collapsed.
Click to expand it.
satella/coding/misc.py
+
12
−
3
View file @
a7bd1227
...
...
@@ -60,7 +60,11 @@ class Closeable:
Can be also used as a context manager, with close() called upon __exit__.
.. warning:: You should extend both __init__ and close(). Invoke __init__() at the end of
your class constructor, this will prevent the destructor from closing on half-initialized classes.
your class constructor, this will prevent the destructor from closing on half-initialized
classes.
Objects before initialization (calling of this constructor) are considered closed.
Checking if they are closed will emit a warning.
"""
__slots__
=
'
__finalized
'
,
...
...
@@ -72,7 +76,12 @@ class Closeable:
"""
:return: whether this object is closed
"""
return
self
.
__finalized
try
:
return
self
.
__finalized
except
AttributeError
:
warnings
.
warn
(
'
You are checking whether a non-initialized object was closed
'
,
UserWarning
)
return
True
def
close
(
self
)
->
bool
:
"""
...
...
@@ -91,7 +100,7 @@ class Closeable:
try
:
return
not
self
.
__finalized
except
AttributeError
:
return
False
# the device does not need clean up
warnings
.
warn
(
'
Attempted to clean up a non-initialized object
'
,
UserWarning
)
finally
:
self
.
__finalized
=
True
...
...
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