Skip to content

Add importlib.metadata (Python >= 3.8) #3346

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 6 commits into from
Oct 30, 2019

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Oct 11, 2019

Part of #3319

@srittau
Copy link
Collaborator Author

srittau commented Oct 11, 2019

@rchen152 I have another pytype failure that I am unclear about: https://travis-ci.org/python/typeshed/jobs/596595124. "TypeError: Unexpected definition type <class 'NoneType'>", although all uses of None look ok to me and not like something that hasn't been done before in other stubs. Maybe it's the @overload + @classmethod? Unfortunately I can't get pytype to run locally:

$ ~/.pyenv/versions/3.6.9/bin/pytype stdlib/3/importlib/metadata.pyi 
usage: pytype [options] input [input ...]
pytype: error: Need an input.

@rchen152
Copy link
Collaborator

I'll take a look. To run pytype locally, the command is pytype-single --parse-pyi --module-name=<whatever> -V<major.minor> <filepath>.

@rchen152
Copy link
Collaborator

Huh. pytype can't parse nested classes inside a version check.

class Foo:
  class Bar: ...

parses fine.

if sys.version_info >= (3, 8):
  class Foo:
    class Bar: ...

crashes the parser. I'll work on a fix.

rchen152 added a commit to google/pytype that referenced this pull request Oct 15, 2019
rchen152 added a commit to google/pytype that referenced this pull request Oct 15, 2019
rchen152 added a commit to google/pytype that referenced this pull request Oct 15, 2019
@srittau
Copy link
Collaborator Author

srittau commented Oct 18, 2019

This passes CI now

class DistributionFinder(MetaPathFinder):
class Context:
name: Optional[str]
def __init__(self, *, name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

Does it really need to be a list? The implementation doesn't seem to impose strong requirements, so Sequence would be better. This also applies to line 40 above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

path is returned literally from Context.path, so we'd need to change that return value as well to match. I believe this is mostly meant for internal use in MetadataPathFinder.find_distributions(), which would accept an iterable as well, so we probably could change this without affecting users. It's a tradeoff, I can change it to whatever you prefer.

@JelleZijlstra JelleZijlstra merged commit c8405bb into python:master Oct 30, 2019
@srittau srittau deleted the importlib-metadata branch October 30, 2019 07:11
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.

3 participants