-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add all the files which pytype fails on during import. #1720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
All of these files can not be used with pytype at HEAD. They fail during import with various error messages.
tests/pytype_blacklist.txt
Outdated
stdlib/3/io.pyi | ||
stdlib/3/calendar.pyi | ||
stdlib/3/fcntl.pyi | ||
stdlib/3/gzip.pyi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we didn't have to blacklist these before? The existing travis tests do check the pyi parsing step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change blacklists all files which will kill PyType if actually used. The above listed files depend on stdlib/3/builtins.pyi which contains line 241:
"def center(self, width: int, fillchar: str = ' ') -> str: ..."
ParseError: File: "pytype/typeshed/stdlib/3/builtins.pyi", line 241
def center(self, width: int, fillchar: str = ' ') -> str: ...
^
ParseError: syntax error, unexpected ')', expecting NAME or NUMBER or ELLIPSIS
The travis tests just try to parse each file in isolation and can therefore not see this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That particular error is because of the ' '
default, right? That seems easy to fix at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #1721 to change the defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually want to use typeshed's builtins.pyi
with pytype, though, since we have our own (__bulitin__.pytd
). We're probably just missing a symlink builtins.pytd -> __builtin__.pytd
in pytype/pytd/builtins
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It becomes a BadDependency Error once builtins.pyi is changed. As the pytype typing module does not have all the things needed.
You can fix that in builtins.pyi though. Replace ' ' with ...
…On Nov 8, 2017 7:58 AM, "Sebastian Steenbuck" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In tests/pytype_blacklist.txt
<#1720 (comment)>:
> # pytype doesn't yet support aliases with implicit type parameters
# (e.g., here, FutureT = Future[T])
stdlib/3.4/asyncio/tasks.pyi
+
+# ParseError: syntax error, unexpected ')', expecting NAME or NUMBER or
+# ELLIPSIS
+stdlib/2and3/locale.pyi
+stdlib/3/io.pyi
+stdlib/3/calendar.pyi
+stdlib/3/fcntl.pyi
+stdlib/3/gzip.pyi
This change blacklists all files which will kill PyType if actually used.
The above listed files depend on stdlib/3/builtins.pyi which contains line
241:
"def center(self, width: int, fillchar: str = ' ') -> str: ..."
ParseError: File: "pytype/typeshed/stdlib/3/builtins.pyi", line 241
def center(self, width: int, fillchar: str = ' ') -> str: ...
^
ParseError: syntax error, unexpected ')', expecting NAME or NUMBER or
ELLIPSIS
The travis tests just try to parse each file in isolation and can
therefore not see this issue.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1720 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMlaU0IhWl3C7XY-ogUbaI4KCJSxiks5s0c-jgaJpZM4QWVW->
.
|
Oh, BTW, we should probably get rid of symlinks, not add more. They don't
work on Windows (at least, not without Administrator privileges).
See python/mypy#4143 (comment)
|
tests/pytype_blacklist.txt
Outdated
@@ -1,13 +1,116 @@ | |||
# Pytype blacklist. Files will not be tested with pytype. | |||
# Pytype blacklist. Files will not be tested with pytype. Notice that the parse | |||
# test will work for some of the files. Loading the files will fail, but is not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make typeshed's pytype tests also load these files? It's not ideal if the typeshed project has to maintain a blacklist file without a test to ensure the blacklist is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This will take a few more days. The code path to easily test this is not yet in PyType's github repo.
Fixes a pytype issue from #1720.
This change will make the test script actually load the files and all dependencies of it, instead of just verifying that it can be parsed.
I updated the pytype_test script to use pytype instead of pytd and updated the blacklist accordingly. This is not a perfect change, it would be nicer to actually test with Python 3.6 for the stdlib/3.X files but that is too much for this change and should be done in a different one. |
A green travis run is at https://travis-ci.org/x3k6a2/typeshed/builds/300136808 . Afaik I can't request a rerun for the failed integration check. |
Just restarted the Travis build. |
* don't import enum in Python 2 Fixes a pytype issue from #1720. * move enums together
This list was generated by running pytype with more options. 1: typeshed-location was pointed to the current typeshed instead of the one shipped with pytype. 2: --module-name=<foo> was provided as a parameter. Without this parameter wildcard imports "from _ast import *" misbehave. Files with a "# parse only" comment will only be parsed and not loaded.
This change adds the ability to either run pytype or pytd, based on a "# parse only" comment in pytype_blacklist.pytd
As discussed offline: |
The files tries to load builtins which are not defined for python2.
* Replace " with ' everywhere were it was used. * Move the multi line parameters around to allow for something the linter will accept.
tests/pytype_test.py
Outdated
sys.exit(1) | ||
|
||
_PARSE_ONLY_REGEX = r'\s*#\s*parse only\s*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the re.compile right here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obsolete, done in another place.
tests/pytype_test.py
Outdated
parse_only_re = re.compile(_PARSE_ONLY_REGEX) | ||
for f in lines: | ||
if parse_only_re.search(f): | ||
parse_only.append(f.split('#')[0].strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the regexp so that you can do
match = parse_only_re.match(f)
if match:
parse_only.append(match.group(1))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored so that the regexes are independent of each other.
tests/pytype_test.py
Outdated
wanted = re.compile(r"stdlib/.*\.pyi$") | ||
skipped = re.compile("(%s)$" % "|".join(load_blacklist())) | ||
files = [] | ||
blacklist, parse_only = load_blacklist() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"parse_only" is from the blacklist, too, so that variable name is a bit confusing.
Rename blacklist
to skip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/pytype_test.py
Outdated
['pytype', | ||
'--typeshed-location=%s' % os.getcwd(), | ||
'--module-name=%s' % _get_module_name(f), | ||
'--convert-to-pickle=%s' % temp.name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the temporary file? Or could you just use os.devnull
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/pytype_test.py
Outdated
return max_code, runs | ||
|
||
def _get_module_name(filename): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this above the location where it's called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
All of these files can not be used with pytype at HEAD. They fail during import with various error messages.