Skip to content

clarification around Python 2.7 per-argument type comments #237

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

Closed
ddfisher opened this issue Jun 23, 2016 · 2 comments
Closed

clarification around Python 2.7 per-argument type comments #237

ddfisher opened this issue Jun 23, 2016 · 2 comments

Comments

@ddfisher
Copy link

After implementing per-argument type comments in the mypy (and the typed_ast library it uses), there are a few points in the PEP that might be worthy of clarification/further specification.

  1. It doesn't make sense for an argument to have both a type annotation and a type comment, but I don't think the PEP mentions that that is disallowed. It probably should.

  2. My reading of the PEP suggests this is already the case, but it could be worth being explicit that you don't have to specify a return type to use per-argument type comments.

  3. Would it be acceptable to only allow per-argument type comments after an argument's associated comma, if any?
    E.g. this is acceptable:

def f(x,  # type: int
      y   # type: str
     ):
    pass

but this would not be:

def f( x  # type: int
     , y  # type: str
     ):
    pass

The first form is generally considered more Pythonic, and supporting the second form would add significant implementation complexity.

@gvanrossum
Copy link
Member

  1. It doesn't make sense for an argument to have both a type annotation and a type comment, but I don't think the PEP mentions that that is disallowed. It probably should.

Agreed. The PEP already says this, but pretty weakly: "To specify the return type use the ellipsis syntax."

  1. My reading of the PEP suggests this is already the case, but it could be worth being explicit that you don't have to specify a return type to use per-argument type comments.

That same sentence was meant to also cover this. :-) Agreed it's too subtle.

  1. Would it be acceptable to only allow per-argument type comments after an argument's associated comma, if any?

Also agreed. This was implicit in the example. :-)

Do you want to make a PR for the PEP?

@ddfisher
Copy link
Author

Will do, thanks!

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

No branches or pull requests

2 participants