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
76795291
Commit
76795291
authored
Aug 17, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove PyType references
parent
ba744ffa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
57 deletions
+0
-57
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+0
-1
trans/transpiler/phases/initial_pytype/__init__.py
trans/transpiler/phases/initial_pytype/__init__.py
+0
-56
No files found.
trans/transpiler/__init__.py
View file @
76795291
...
...
@@ -173,7 +173,6 @@ else:
def
transpile
(
source
,
name
=
"<module>"
,
path
=
None
):
TB
=
f"transpiling module
{
cf
.
white
(
name
)
}
"
res
=
ast
.
parse
(
source
,
type_comments
=
True
)
# res = initial_pytype.run(source, res)
IfMainVisitor
().
visit
(
res
)
res
=
DesugarWith
().
visit
(
res
)
...
...
trans/transpiler/phases/initial_pytype/__init__.py
deleted
100644 → 0
View file @
ba744ffa
import
ast
import
pytype.config
from
pytype
import
io
from
pytype.pytd
import
pytd_utils
from
pytype.tools.traces
import
traces
def
run
(
source
:
str
,
module
:
ast
.
Module
)
->
ast
.
Module
:
opt
=
pytype
.
config
.
Options
.
create
(
None
,
no_return_any
=
True
,
precise_return
=
True
)
source_code
=
infer_types
(
source
,
opt
)
visitor
=
AnnotateAstVisitor
(
source_code
,
ast
)
visitor
.
visit
(
module
)
return
module
def
infer_types
(
source
:
str
,
options
:
pytype
.
config
.
Options
)
->
"source.Code"
:
with
io
.
wrap_pytype_exceptions
(
PytypeError
,
filename
=
options
.
input
):
return
traces
.
trace
(
source
,
options
)
class
AnnotateAstVisitor
(
traces
.
MatchAstVisitor
):
def
visit_Name
(
self
,
node
):
self
.
_maybe_annotate
(
node
)
def
visit_Attribute
(
self
,
node
):
self
.
_maybe_annotate
(
node
)
def
visit_FunctionDef
(
self
,
node
):
self
.
_maybe_annotate
(
node
)
def
_maybe_annotate
(
self
,
node
):
"""Annotates a node."""
try
:
ops
=
self
.
match
(
node
)
except
NotImplementedError
:
return
# For lack of a better option, take the first one.
unused_loc
,
entry
=
next
(
iter
(
ops
),
(
None
,
None
))
self
.
_maybe_set_type
(
node
,
entry
)
def
_maybe_set_type
(
self
,
node
,
trace
):
"""Sets type information on the node, if there is any to set."""
if
not
trace
:
return
node
.
resolved_type
=
trace
.
types
[
-
1
]
node
.
resolved_annotation
=
_annotation_str_from_type_def
(
trace
.
types
[
-
1
])
class
PytypeError
(
Exception
):
"""Wrap exceptions raised by Pytype."""
def
_annotation_str_from_type_def
(
type_def
):
return
pytd_utils
.
Print
(
type_def
)
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