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
9e0f4f36
Commit
9e0f4f36
authored
May 29, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forbid use of raw type variable
parent
8cadfa12
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
7 deletions
+7
-7
trans/stdlib/__init__.py
trans/stdlib/__init__.py
+1
-3
trans/transpiler/phases/typing/annotations.py
trans/transpiler/phases/typing/annotations.py
+3
-3
trans/transpiler/phases/typing/expr.py
trans/transpiler/phases/typing/expr.py
+2
-0
trans/transpiler/phases/typing/stdlib.py
trans/transpiler/phases/typing/stdlib.py
+1
-1
No files found.
trans/stdlib/__init__.py
View file @
9e0f4f36
...
...
@@ -50,9 +50,7 @@ def identity_2(x: U, y: V) -> Tuple[U, V]:
assert
list
.
__add__
assert
list
.
__add__
([
5
],
[[
6
][
0
]])
assert
list
[
U
].
__add__
assert
list
[
U
].
__add__
([
1
],
[
2
])
assert
list
[
U
].
__add__
#assert list[U].__add__
assert
list
[
int
].
__add__
assert
identity_2
(
1
,
"a"
)
assert
lambda
x
,
y
:
identity_2
(
x
,
y
)
...
...
trans/transpiler/phases/typing/annotations.py
View file @
9e0f4f36
...
...
@@ -18,11 +18,11 @@ class TypeAnnotationVisitor(NodeVisitorSeq):
return
TY_SELF
if
existing
:
=
self
.
scope
.
get
(
node
):
ty
=
existing
.
type
if
isinstance
(
ty
,
TypeVariable
):
if
isinstance
(
ty
,
Type
Type
)
and
isinstance
(
ty
.
type_object
,
Type
Variable
):
if
existing
is
not
self
.
scope
.
vars
.
get
(
node
,
None
):
# Type variable from outer scope, so we copy it
ty
=
TypeVariable
(
ty
.
name
)
self
.
scope
.
declare_local
(
node
,
ty
)
# todo: unneeded?
ty
=
TypeVariable
(
ty
.
type_object
.
name
)
self
.
scope
.
declare_local
(
node
,
TypeType
(
ty
)
)
# todo: unneeded?
self
.
typevars
.
append
(
ty
)
if
isinstance
(
ty
,
TypeType
):
return
ty
.
type_object
...
...
trans/transpiler/phases/typing/expr.py
View file @
9e0f4f36
...
...
@@ -74,6 +74,8 @@ class ScoperExprVisitor(ScoperVisitor):
obj
=
self
.
scope
.
get
(
node
.
id
)
if
not
obj
:
raise
NameError
(
f"Name
{
node
.
id
}
is not defined"
)
if
isinstance
(
obj
.
type
,
TypeType
)
and
isinstance
(
obj
.
type
.
type_object
,
TypeVariable
):
raise
NameError
(
f"Use of type variable"
)
return
obj
.
type
def
visit_Compare
(
self
,
node
:
ast
.
Compare
)
->
BaseType
:
...
...
trans/transpiler/phases/typing/stdlib.py
View file @
9e0f4f36
...
...
@@ -81,7 +81,7 @@ class StdlibVisitor(NodeVisitorSeq):
def
visit_Call
(
self
,
node
:
ast
.
Call
)
->
BaseType
:
ty_op
=
self
.
visit
(
node
.
func
)
if
isinstance
(
ty_op
,
TypeType
):
return
ty_op
.
type_object
(
*
[
ast
.
literal_eval
(
arg
)
for
arg
in
node
.
args
]
)
return
TypeType
(
ty_op
.
type_object
(
*
[
ast
.
literal_eval
(
arg
)
for
arg
in
node
.
args
])
)
raise
NotImplementedError
(
ast
.
unparse
(
node
))
def
anno
(
self
)
->
"TypeAnnotationVisitor"
:
...
...
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