Giter Site home page Giter Site logo

Comments (4)

bocekm avatar bocekm commented on August 23, 2024
class MyActor(Actor):
    """
    This is a lengthy
    multiline docstring.
    """
    name = 'my_actor'

    def process(self):
       """Short one-line docstring."""
       mutliline_string_variable = (
           'I am a multiline string.\n'
           'This is my second line.'
       )

from leapp-repository.

bocekm avatar bocekm commented on August 23, 2024

@vinzenz, @shaded-enmity, on Cabal we have agreed on the following multiline string formatting, which is actually incorrect as it includes whitespaces you most of the times don't want:

class MyClass():
    multiline_attribute = '''
        I hold some lengthy
        multiline string.
    '''

Take a look if you fancy the alternative formatting I used in the previous comment. I think it's better than:

mutliline_string_variable = 'I am a multiline string.\n' \
                            'This is my second line.'

I fear neither look pythonic enough for you. If so, propose another.

from leapp-repository.

vojtechsokol avatar vojtechsokol commented on August 23, 2024

What about this for multiline strings?

multiline_string = ('first line',
                    'second line')

And regarding multiline docstring, why not use PEP257? I.e. for one liner a phrase (ending in a period) with opening and closing quotes on the same line and for multi-line docstring the first line would be the same phrase, followed by a blank line, followed by a more elaborate description:

class SimpleClass(Object):
    """This is a simple class."""

class ComplicatedClass(Object):
    """
    This is a more complicated class.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc porta sed
    urna venenatis faucibus. Phasellus at bibendum ligula, a posuere metus.
    """

from leapp-repository.

bocekm avatar bocekm commented on August 23, 2024

The multiline_string you propose is actually a tuple. So, yeah, in general I'm for the parenthesis version as I mentioned two comments above.

As to the use of PEP257, the thing is that it allows a bit of variations: "The summary line may be on the same line as the opening quotes or on the next line."
We'll allow just "on the next line". I guess that's the only difference. So I'll leave the PEP257 in the contribution guidelines, and just mention this one difference.

So, to wrap it up, here's the string & docstring formatting:

class MyActor(Actor):
    """
    Start with a single-line brief summary of the actor (under the triple quotes).

    Leave a blank line below the summary and then describe the actor's behaviour
    here in detail.
    """
    name = 'my_actor'

    def process(self):
        """This is a simple method."""
        complicated_method()

    def complicated_method():
        """
        This is a more complicated method.

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc porta sed
        urna venenatis faucibus. Phasellus at bibendum ligula, a posuere metus.
        """
        mutliline_string = (
            'I am a multiline string.\n'
            'This is my second line.'
        )

from leapp-repository.

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.