Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 19 commits into from
Nov 15, 2017

Conversation

x3k6a2
Copy link
Contributor

@x3k6a2 x3k6a2 commented Nov 8, 2017

All of these files can not be used with pytype at HEAD. They fail during import with various error messages.

All of these files can not be used with pytype at HEAD. They fail during import with various error messages.
stdlib/3/io.pyi
stdlib/3/calendar.pyi
stdlib/3/fcntl.pyi
stdlib/3/gzip.pyi
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@x3k6a2 x3k6a2 Nov 8, 2017

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@gvanrossum
Copy link
Member

gvanrossum commented Nov 8, 2017 via email

@gvanrossum
Copy link
Member

gvanrossum commented Nov 8, 2017 via email

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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.

JelleZijlstra added a commit that referenced this pull request Nov 8, 2017
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.
@x3k6a2
Copy link
Contributor Author

x3k6a2 commented Nov 10, 2017

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.

@x3k6a2
Copy link
Contributor Author

x3k6a2 commented Nov 10, 2017

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.
This works now because of the pytype commit google/pytype@0964db4

@JelleZijlstra
Copy link
Member

Just restarted the Travis build.

matthiaskramm pushed a commit that referenced this pull request Nov 10, 2017
* 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
@x3k6a2
Copy link
Contributor Author

x3k6a2 commented Nov 14, 2017

As discussed offline:
1: Added a "# parse only" comment to the 3.x files in the blacklist. Which will make those files be parsed but not loaded.
2: Checked all the stdlib/2.x/ files with exceptions. Most of the exceptions could be removed by providing the --module-name=foo flag. Without it wildcard imports are not handled correctly. The alias for ".*" is not removed by the LookupExternalTypes.VisitTypeDevlUnit visitor. This behavior is a bit surprising.
The only 2.x files added left to be added to the blacklist is os.init.pyi which imports builtins. Builtins is not defined for python2.

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.
sys.exit(1)

_PARSE_ONLY_REGEX = r'\s*#\s*parse only\s*'
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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())
Copy link
Contributor

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))

?

Copy link
Contributor Author

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.

wanted = re.compile(r"stdlib/.*\.pyi$")
skipped = re.compile("(%s)$" % "|".join(load_blacklist()))
files = []
blacklist, parse_only = load_blacklist()
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

['pytype',
'--typeshed-location=%s' % os.getcwd(),
'--module-name=%s' % _get_module_name(f),
'--convert-to-pickle=%s' % temp.name,
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return max_code, runs

def _get_module_name(filename):
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@matthiaskramm matthiaskramm merged commit 8b56c1e into python:master Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants