Code Monkey home page Code Monkey logo

Comments (4)

ethanhs avatar ethanhs commented on June 27, 2024

This syntax is incompatible with PEP 484. See the paragraph here: https://github.com/python/peps/blob/master/pep-0484.txt#L2097

Relevant quote:

you may list the arguments one per line and add a # type: comment
per line after an argument's associated comma

(Emphasis mine)

You may also want to see the discussion in the PR you referenced here: #5 (comment)

from typed_ast.

ddfisher avatar ddfisher commented on June 27, 2024

Great question! The short answer is: no plans currently. Here's why:

First, the major point of departure of typed_ast from ast is that it considers type comments part of the language (which in some senses they are, as specified by PEP 484). As part of this, it considers misplaced type comments to be syntax errors. This is partially due to technical limitations, and I'd likely accept a patch which changed them into warnings, provided it didn't require a massive overhaul.

Second, as @ethanhs mentioned above, PEP 484 is specific about the location of the type comments relative to the comma, so per the spec those type comments are not in a valid position. (IIRC that's partly due to beginning-of-the-line commas being considered unpythonic). It could be valuable for typed_ast to be more flexible here, but I'm not sure it's worth the additional complexity.

The combination of those two factors results in the behavior that you see. Neither of these things has planned development. I've looked at the referenced issue, but could you talk a bit more about why you want this? Maybe a workaround can be found instead.

from typed_ast.

gvanrossum avatar gvanrossum commented on June 27, 2024

Also, I've always despised the style where the comma comes at the start of the next line. It violates esthetics and good sense.

from typed_ast.

mbdevpl avatar mbdevpl commented on June 27, 2024

The code sample above is an example of what my unparser generates. Implementing unparsing in that way was... very simple. And I was surprised that typed_ast errors out on it. But indeed, per PEP 484, a fix should be done not on the parser side, but on the unparser side of things. Thanks for taking time to explain everything!

from typed_ast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.