Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
typon-concurrency
Commits
ab4b30b2
Commit
ab4b30b2
authored
Jun 09, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix generic substitution for methods
parent
23ea132c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
+10
-5
trans/transpiler/phases/typing/types.py
trans/transpiler/phases/typing/types.py
+10
-5
No files found.
trans/transpiler/phases/typing/types.py
View file @
ab4b30b2
...
...
@@ -46,7 +46,7 @@ class BaseType(ABC):
# def clone(self) -> "BaseType":
# pass
def
gen_sub
(
self
,
this
:
"BaseType"
,
typevars
:
Dict
[
str
,
"BaseType"
])
->
"Self"
:
def
gen_sub
(
self
,
this
:
"BaseType"
,
typevars
:
Dict
[
str
,
"BaseType"
]
,
cache
=
None
)
->
"Self"
:
return
self
def
to_list
(
self
)
->
List
[
"BaseType"
]:
...
...
@@ -104,7 +104,7 @@ class TypeVariable(BaseType):
def
contains_internal
(
self
,
other
:
BaseType
)
->
bool
:
return
self
.
resolve
()
is
other
.
resolve
()
def
gen_sub
(
self
,
this
:
"BaseType"
,
typevars
)
->
"Self"
:
def
gen_sub
(
self
,
this
:
"BaseType"
,
typevars
,
cache
=
None
)
->
"Self"
:
if
match
:
=
typevars
.
get
(
self
.
name
):
return
match
return
self
...
...
@@ -193,17 +193,22 @@ class TypeOperator(BaseType, ABC):
def
__hash__
(
self
):
return
hash
((
self
.
name
,
tuple
(
self
.
args
)))
def
gen_sub
(
self
,
this
:
BaseType
,
typevars
)
->
"Self"
:
def
gen_sub
(
self
,
this
:
BaseType
,
typevars
,
cache
=
None
)
->
"Self"
:
cache
=
cache
or
{}
if
me
:
=
cache
.
get
(
self
):
return
me
if
len
(
self
.
args
)
==
0
:
return
self
res
=
object
.
__new__
(
self
.
__class__
)
# todo: ugly... should make a clone()
cache
[
self
]
=
res
if
isinstance
(
this
,
TypeOperator
):
vardict
=
dict
(
zip
(
typevars
.
keys
(),
this
.
args
))
else
:
vardict
=
typevars
for
k
in
dataclasses
.
fields
(
self
):
setattr
(
res
,
k
.
name
,
getattr
(
self
,
k
.
name
))
res
.
args
=
[
arg
.
resolve
().
gen_sub
(
this
,
vardict
)
for
arg
in
self
.
args
]
res
.
args
=
[
arg
.
resolve
().
gen_sub
(
this
,
vardict
,
cache
)
for
arg
in
self
.
args
]
res
.
methods
=
{
k
:
v
.
gen_sub
(
this
,
vardict
,
cache
)
for
k
,
v
in
self
.
methods
.
items
()}
return
res
def
to_list
(
self
)
->
List
[
"BaseType"
]:
...
...
@@ -269,7 +274,7 @@ TY_NONE = TypeOperator([], "NoneType")
TY_MODULE
=
TypeOperator
([],
"module"
)
TY_VARARG
=
TypeOperator
([],
"vararg"
)
TY_SELF
=
TypeOperator
([],
"Self"
)
TY_SELF
.
gen_sub
=
lambda
this
,
typevars
:
this
TY_SELF
.
gen_sub
=
lambda
this
,
typevars
,
_
:
this
class
PyList
(
TypeOperator
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment