Skip to content

Empty class body should pretty print as "pass" #31

Open

Description

@puffnfresh
prettyText $ Py.Class (Py.Ident "Hello" ()) [] [] ()

Should give:

class Hello:
  pass

But currently the "pass" is missing.

Activity

  1. bjpop commented on Aug 3, 2016

    @bjpop
    Owner

    Thanks @puffnfresh.

    I'm not sure how I feel about this.

    On the one hand I can see the convenience, but on the other hand the pretty printer assumes that it is given a valid AST.

    I think the bigger problem is that we don't have a convenient way to construct ASTs programmatically. Therefore we are currently forced to build the AST values directly, but the AST data type has too much slack in it. It is easy to create ASTs which do not correspond to valid Python parses.

    We could patch the pretty printer to allow conveniences, like the one described in this issue. However, that is a bit of a slippery slope, given that there are probably lots of places where such conveniences could be introduced in the pretty printer.

    I think a better solution is to add functionality for conveniently building valid ASTs programmatically, and leave the pretty printer to assume that it is given a valid AST.

    Cheers,
    Bernie

  2. puffnfresh commented on Aug 4, 2016

    @puffnfresh
    Author

    @bjpop I agree:

    data ClassyBody
      = ClassBody (NonEmptyList a)
      | ClassBodyPass
  3. bjpop commented on Aug 10, 2016

    @bjpop
    Owner

    I'm thinking of a library of "smart" constructor functions. Perhaps also quasi quotation, as mentioned in #13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions