Skip to content

Eliminate some conditional method defs in fastparse #5499

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
Aug 17, 2018

Conversation

msullivan
Copy link
Collaborator

It seems like they might not be necessary anymore, and mypyc doesn't
support it.

It seems like they might not be necessary anymore, and mypyc doesn't
support it.
@msullivan msullivan requested a review from ilevkivskyi August 17, 2018 21:58
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Looks good, but there is a problem.

@overload
def visit(self, node: ast3.expr) -> Type: ...
@overload
def visit(self, node: ast3.expr) -> Type: ...
Copy link
Member

Choose a reason for hiding this comment

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

This will fail on 3.5.1

def visit(self, node: Optional[ast3.AST]) -> Any:
return self._visit_implementation(node)
def visit(self, node: Optional[ast3.AST]) -> Optional[Type]: # noqa
return self._visit_implementation(node)
Copy link
Member

Choose a reason for hiding this comment

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

Also I think _visit_implementation only existed because of conditional definition, you can kill it now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

✔️

@@ -67,6 +67,13 @@
TYPE_COMMENT_AST_ERROR = 'invalid type comment or annotation'


# Older versions of typing don't allow using overload outside stubs,
# so provide a dummy.
if sys.version_info < (3, 6):
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be guarded with a big if not MYPY:?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mypy didn't seem to care, but probably ought to anyways

Copy link
Member

Choose a reason for hiding this comment

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

On 3.4, the version of typing is newer than on 3.5, so you lose some type safety on 3.4. It works because you are only making the signature less exact, but it is more correct to use if MYPY.

@msullivan msullivan merged commit 1adacd0 into master Aug 17, 2018
@msullivan msullivan deleted the fastparse_cleanup branch August 17, 2018 22:51
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