Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gboml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
smart_grids
public
gboml
Commits
7312d68d
Commit
7312d68d
authored
2 years ago
by
Derval Guillaume
Browse files
Options
Downloads
Patches
Plain Diff
Fix a bug in tree modifier + typing
parent
4f502cce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gboml/ast/base.py
+5
-1
5 additions, 1 deletion
src/gboml/ast/base.py
src/gboml/redundant_definitions.py
+1
-1
1 addition, 1 deletion
src/gboml/redundant_definitions.py
src/gboml/tools/tree_modifier.py
+6
-2
6 additions, 2 deletions
src/gboml/tools/tree_modifier.py
with
12 additions
and
4 deletions
src/gboml/ast/base.py
+
5
−
1
View file @
7312d68d
import
typing
from
dataclasses
import
dataclass
,
field
from
dataclasses
import
dataclass
,
field
from
typing
import
Optional
from
typing
import
Optional
...
@@ -15,4 +16,7 @@ class GBOMLObject:
...
@@ -15,4 +16,7 @@ class GBOMLObject:
@dataclass
@dataclass
class
NamedGBOMLObject
(
GBOMLObject
):
class
NamedGBOMLObject
(
GBOMLObject
):
name
:
str
name
:
str
\ No newline at end of file
AnyGBOMLObject
=
typing
.
TypeVar
(
'
AnyGBOMLObject
'
,
bound
=
GBOMLObject
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/gboml/redundant_definitions.py
+
1
−
1
View file @
7312d68d
...
@@ -46,7 +46,7 @@ from gboml.ast import *
...
@@ -46,7 +46,7 @@ from gboml.ast import *
from
gboml.tools.tree_modifier
import
modify
from
gboml.tools.tree_modifier
import
modify
def
remove_redundant_definitions
(
elem
:
GBOMLObject
)
->
GBOMLObject
:
def
remove_redundant_definitions
(
elem
:
Any
GBOMLObject
)
->
Any
GBOMLObject
:
return
modify
(
elem
,
{
Node
:
_modify_node
,
HyperEdge
:
_modify_hyperedge
})
return
modify
(
elem
,
{
Node
:
_modify_node
,
HyperEdge
:
_modify_hyperedge
})
...
...
This diff is collapsed.
Click to expand it.
src/gboml/tools/tree_modifier.py
+
6
−
2
View file @
7312d68d
...
@@ -124,7 +124,8 @@ def _modify_gbomlobject(obj, by):
...
@@ -124,7 +124,8 @@ def _modify_gbomlobject(obj, by):
# if we now what to do with the current object, let's do it
# if we now what to do with the current object, let's do it
for
x
in
family_list
[
obj
.
__class__
]:
for
x
in
family_list
[
obj
.
__class__
]:
if
x
in
by
:
if
x
in
by
:
return
by
[
x
](
obj
)
obj
=
by
[
x
](
obj
)
break
# and now the hard part
# and now the hard part
interesting_fields
=
set
()
interesting_fields
=
set
()
...
@@ -141,7 +142,10 @@ def _modify_gbomlobject(obj, by):
...
@@ -141,7 +142,10 @@ def _modify_gbomlobject(obj, by):
return
obj
return
obj
def
modify
(
element
:
typing
.
Any
,
by
:
dict
[
typing
.
Type
[
GBOMLObject
],
typing
.
Callable
[[
GBOMLObject
],
GBOMLObject
]]):
T
=
typing
.
TypeVar
(
'
T
'
)
def
modify
(
element
:
T
,
by
:
dict
[
typing
.
Type
[
AnyGBOMLObject
],
typing
.
Callable
[[
AnyGBOMLObject
],
AnyGBOMLObject
]])
->
T
:
"""
"""
Recursively modifies a GBOMLGraph tree (or any part of it) according to rules set in the dict `by`.
Recursively modifies a GBOMLGraph tree (or any part of it) according to rules set in the dict `by`.
`by` entries should be in the form `(cls: fun)`, where cls is a class derivating from GBOMLObject and
`by` entries should be in the form `(cls: fun)`, where cls is a class derivating from GBOMLObject and
...
...
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