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
baa4b569
Commit
baa4b569
authored
1 year ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix Optional
parent
995eef03
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
satella/coding/optionals.py
+14
-11
14 additions, 11 deletions
satella/coding/optionals.py
with
15 additions
and
11 deletions
CHANGELOG.md
+
1
−
0
View file @
baa4b569
...
@@ -5,3 +5,4 @@
...
@@ -5,3 +5,4 @@
*
added a way to register an object to be cleaned up via MemoryPressureManager
*
added a way to register an object to be cleaned up via MemoryPressureManager
*
fixed get_own_cpu_usage() to work on Windows
*
fixed get_own_cpu_usage() to work on Windows
*
added __len__ to Optional
*
added __len__ to Optional
*
major bugfix in Optional
This diff is collapsed.
Click to expand it.
satella/coding/optionals.py
+
14
−
11
View file @
baa4b569
...
@@ -77,33 +77,36 @@ class Optional(Proxy[T]):
...
@@ -77,33 +77,36 @@ class Optional(Proxy[T]):
return
other
==
me
return
other
==
me
def
__getattr__
(
self
,
item
):
def
__getattr__
(
self
,
item
):
return
EMPTY_OPTIONAL
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
else
super
().
__getattr__
(
item
)
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
EMPTY_OPTIONAL
if
obj
is
None
else
getattr
(
obj
,
item
)
def
__call__
(
self
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
EMPTY_OPTIONAL
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
else
super
().
__call__
(
*
args
,
**
kwargs
)
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
EMPTY_OPTIONAL
if
obj
is
None
else
obj
(
*
args
,
**
kwargs
)
def
__bool__
(
self
):
def
__bool__
(
self
):
return
False
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
else
super
().
__bool__
()
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
False
if
obj
is
None
else
bool
(
obj
)
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
return
EMPTY_OPTIONAL
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
else
super
().
__getattr__
(
item
)
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
EMPTY_OPTIONAL
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
else
obj
[
item
]
def
__setitem__
(
self
,
key
,
value
)
->
None
:
def
__setitem__
(
self
,
key
,
value
)
->
None
:
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
:
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
if
obj
is
not
None
:
super
()
.
__setitem__
(
key
,
value
)
obj
.
__setitem__
(
key
,
value
)
def
__delitem__
(
self
,
key
)
->
None
:
def
__delitem__
(
self
,
key
)
->
None
:
if
getattr
(
self
,
'
_Proxy__obj
'
)
is
None
:
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
if
obj
is
not
None
:
super
().
__delitem__
(
key
)
del
obj
[
key
]
def
__len__
(
self
)
->
int
:
def
__len__
(
self
)
->
int
:
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
obj
=
getattr
(
self
,
'
_Proxy__obj
'
)
return
0
if
obj
is
None
else
len
(
obj
)
return
0
if
obj
is
None
else
len
(
obj
)
EMPTY_OPTIONAL
=
Optional
(
None
)
EMPTY_OPTIONAL
=
Optional
(
None
)
...
...
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