Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
1d01f99a
Commit
1d01f99a
authored
Jul 07, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `Self` handling in classes
parent
02527c92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
trans/transpiler/phases/typing/annotations.py
trans/transpiler/phases/typing/annotations.py
+4
-1
trans/transpiler/phases/typing/block.py
trans/transpiler/phases/typing/block.py
+3
-2
No files found.
trans/transpiler/phases/typing/annotations.py
View file @
1d01f99a
...
@@ -15,7 +15,10 @@ class TypeAnnotationVisitor(NodeVisitorSeq):
...
@@ -15,7 +15,10 @@ class TypeAnnotationVisitor(NodeVisitorSeq):
def
visit_str
(
self
,
node
:
str
)
->
BaseType
:
def
visit_str
(
self
,
node
:
str
)
->
BaseType
:
if
node
in
(
"Self"
,
"self"
)
and
self
.
cur_class
:
if
node
in
(
"Self"
,
"self"
)
and
self
.
cur_class
:
return
TY_SELF
if
isinstance
(
self
.
cur_class
.
type_object
,
abc
.
ABCMeta
)
or
self
.
cur_class
.
type_object
.
is_protocol_gen
or
self
.
cur_class
.
type_object
.
is_protocol
:
return
TY_SELF
else
:
return
self
.
cur_class
.
type_object
if
existing
:
=
self
.
scope
.
get
(
node
):
if
existing
:
=
self
.
scope
.
get
(
node
):
ty
=
existing
.
type
ty
=
existing
.
type
if
isinstance
(
ty
,
TypeType
)
and
isinstance
(
ty
.
type_object
,
TypeVariable
):
if
isinstance
(
ty
,
TypeType
)
and
isinstance
(
ty
.
type_object
,
TypeVariable
):
...
...
trans/transpiler/phases/typing/block.py
View file @
1d01f99a
...
@@ -116,13 +116,14 @@ class ScoperBlockVisitor(ScoperVisitor):
...
@@ -116,13 +116,14 @@ class ScoperBlockVisitor(ScoperVisitor):
def
visit_ClassDef
(
self
,
node
:
ast
.
ClassDef
):
def
visit_ClassDef
(
self
,
node
:
ast
.
ClassDef
):
ctype
=
UserType
(
node
.
name
)
ctype
=
UserType
(
node
.
name
)
self
.
scope
.
vars
[
node
.
name
]
=
VarDecl
(
VarKind
.
LOCAL
,
TypeType
(
ctype
))
cttype
=
TypeType
(
ctype
)
self
.
scope
.
vars
[
node
.
name
]
=
VarDecl
(
VarKind
.
LOCAL
,
cttype
)
scope
=
self
.
scope
.
child
(
ScopeKind
.
CLASS
)
scope
=
self
.
scope
.
child
(
ScopeKind
.
CLASS
)
scope
.
obj_type
=
ctype
scope
.
obj_type
=
ctype
scope
.
class_
=
scope
scope
.
class_
=
scope
node
.
inner_scope
=
scope
node
.
inner_scope
=
scope
node
.
type
=
ctype
node
.
type
=
ctype
visitor
=
ScoperClassVisitor
(
scope
)
visitor
=
ScoperClassVisitor
(
scope
,
cur_class
=
cttype
)
visitor
.
visit_block
(
node
.
body
)
visitor
.
visit_block
(
node
.
body
)
def
visit_If
(
self
,
node
:
ast
.
If
):
def
visit_If
(
self
,
node
:
ast
.
If
):
...
...
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