Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
49bc28c5
Commit
49bc28c5
authored
4 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Change MethodT
parent
7268bf6e
No related branches found
No related tags found
1 merge request
!1
First try of type hints
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libs/lib/xaal/lib/devices.py
+6
-9
6 additions, 9 deletions
libs/lib/xaal/lib/devices.py
with
6 additions
and
9 deletions
libs/lib/xaal/lib/devices.py
+
6
−
9
View file @
49bc28c5
...
@@ -33,12 +33,9 @@ if typing.TYPE_CHECKING:
...
@@ -33,12 +33,9 @@ if typing.TYPE_CHECKING:
from
.engine
import
Engine
from
.engine
import
Engine
from
.core
import
EngineMixin
from
.core
import
EngineMixin
# Funtion type with any arguments and return a dict or None (device methods)
# Funtion types with any arguments and return a dict or None (device methods)
MethodT
=
TypeVar
(
SyncMethodT
=
Callable
[...,
Union
[
dict
,
None
]]
# Fonction synchrone qui retourne un dict ou None
"
MethodT
"
,
AsyncMethodT
=
Callable
[...,
Awaitable
[
Union
[
dict
,
None
]]]
# Coroutine qui retourne un dict ou None
Callable
[...,
Union
[
dict
,
None
]],
Callable
[...,
Awaitable
[
Union
[
dict
,
None
]]]
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -137,7 +134,7 @@ class Device(object):
...
@@ -137,7 +134,7 @@ class Device(object):
self
.
next_alive
=
0
self
.
next_alive
=
0
# Default attributes & methods
# Default attributes & methods
self
.
__attributes
=
Attributes
()
self
.
__attributes
=
Attributes
()
self
.
methods
=
{
self
.
methods
:
dict
[
str
,
Union
[
SyncMethodT
,
AsyncMethodT
]]
=
{
'
get_attributes
'
:
self
.
_get_attributes
,
'
get_attributes
'
:
self
.
_get_attributes
,
'
get_description
'
:
self
.
_get_description
,
'
get_description
'
:
self
.
_get_description
,
}
}
...
@@ -222,14 +219,14 @@ class Device(object):
...
@@ -222,14 +219,14 @@ class Device(object):
else
:
else
:
raise
DeviceError
(
"
Invalid attributes list, use class Attributes)
"
)
raise
DeviceError
(
"
Invalid attributes list, use class Attributes)
"
)
def
add_method
(
self
,
name
:
str
,
func
:
MethodT
):
def
add_method
(
self
,
name
:
str
,
func
:
Union
[
SyncMethodT
,
AsyncMethodT
]
):
self
.
methods
.
update
({
name
:
func
})
self
.
methods
.
update
({
name
:
func
})
def
del_method
(
self
,
name
:
str
):
def
del_method
(
self
,
name
:
str
):
if
name
in
self
.
methods
:
if
name
in
self
.
methods
:
del
self
.
methods
[
name
]
del
self
.
methods
[
name
]
def
get_methods
(
self
)
->
dict
:
def
get_methods
(
self
)
->
dict
[
str
,
Union
[
SyncMethodT
,
AsyncMethodT
]]
:
return
self
.
methods
return
self
.
methods
def
update_alive
(
self
):
def
update_alive
(
self
):
...
...
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