Skip to content
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

[WIP] Begin implementing PEP 561 checking #4278

Closed
wants to merge 1 commit into from

Conversation

emmatyping
Copy link
Collaborator

@emmatyping emmatyping commented Nov 22, 2017

This is the initial work to add checking using packages that opt into type checking via
PEP 561.

TODO:

- [ ] Namespace package support (awaiting #4277) I'm going ahead without this.

  • Tests (installing packages etc is going to be interesting...)
  • Check PEP 561 conformance to resolution order
  • ignore errors in these files.
  • support running with alternate Python version.
  • document how to make a package compatible.

As of right now, you can install regular packages with types and third party stub packages and they should be picked up. $MYPYPATH supersedes both types of packages, and third-party stubs supersede bundled type packages per PEP 561. Errors in installed packages should be ignored.

Questions:
- Should this be behind a flag?
- Should errors that are ignored in typeshed be ignored for these packages too? I'm not too keen on this, but open to recommendations.

This is the initial work to add packages that opt into type checking via
PEP 561.
@@ -792,6 +792,21 @@ def find() -> Optional[str]:
dir = os.path.normpath(os.path.join(pathitem, dir_chain))
if os.path.isdir(dir):
dirs.append(dir)
try:
user_dir = site.getusersitepackages()
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this use the site packages of the mypy installation, not that of the code being typechecked?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I need to add that. Thanks for the reminder!

@JelleZijlstra
Copy link
Member

I think we should suppress errors in these packages, although I haven't thought deeply about the exact semantics required.

The general reasoning is that third-party packages aren't code the user controls. If I use mypy with --disallow-untyped-defs, start using lxml, and install the lxml-stubs package, I don't want to get errors saying the lxml stubs are missing annotations, because I can't do anything about it.

@JelleZijlstra
Copy link
Member

Also, I don't think it needs to be behind a flag.

@emmatyping
Copy link
Collaborator Author

Namespace package (PEP 420) support should probably wait until it is generally supported in mypy (see #4277), so I removed that from the TODO list for this PR.

It seems that subprocess is being rather uncooperative (not capturing stdout), thus I need to experiment a bit more about capturing the output of invoked Python.

Also, ignoring errors in installed packages should be an easy change, so I will implement that.

@emmatyping
Copy link
Collaborator Author

I'm afraid I've run out of time, and will it will be a few weeks before I can finish this, which is probably better anyway so that #4277 can be done before I complete this.

@emmatyping
Copy link
Collaborator Author

Closing in favor of #4403 for simplicity.

@emmatyping emmatyping closed this Dec 22, 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.

2 participants