Bug with docstrings within init python

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Bug with docstrings within init python

#1 Post by synedraacus »

When using docstrings in functions defined inside init python modules, docstrings marked with three single quotes cause crash with unexpected indent, while docstrings with triple double quotes don't.

This piece of code crashes the game (note the function called 'deck'):

Code: Select all

init -3 python:
    import pygame
    SUITS={u'С':u'Сила',
        u'Д':u'Деньги',
        u'З':u'Знания',
        u'И':u'Интриги'}

    DEFAULT_HISTORY = u'Вам не известна история этой карты'
    #  SPENDABLE_COLOR and PERMANENT_COLOR are used by a format method, so they are without '#'
    SPENDABLE_COLOR = 'AAAAAA'
    PERMANENT_COLOR = 'DEC666'
    COST_QOTIENT = 1.5 #  Cost-to-nominal ratio for trading system

    #  Various utility functions

    def deck(deckline):
        '''
        Given a deck-describing line, return a list of cards.\
        Line syntax is like 0С2Д2Д, etc. etc. Number, then suit, repeat for all cards\
        '0' means '10' because fuck you, that's why\
        '''
        if not (type(deckline) == unicode):
            raise TypeError('Only unicode line accepted by deck constructor')
        d = []
        l=list(deckline)
        while len(l)>0:
            num = int(l.pop(0))
            suit = l.pop(0)
            d.append(Card(suit, num))
        return d
This one doesn't:

Code: Select all

init -3 python:
    import pygame
    SUITS={u'С':u'Сила',
        u'Д':u'Деньги',
        u'З':u'Знания',
        u'И':u'Интриги'}

    DEFAULT_HISTORY = u'Вам не известна история этой карты'
    #  SPENDABLE_COLOR and PERMANENT_COLOR are used by a format method, so they are without '#'
    SPENDABLE_COLOR = 'AAAAAA'
    PERMANENT_COLOR = 'DEC666'
    COST_QOTIENT = 1.5 #  Cost-to-nominal ratio for trading system

    #  Various utility functions

    def deck(deckline):
        """
        Given a deck-describing line, return a list of cards.\
        Line syntax is like 0С2Д2Д, etc. etc. Number, then suit, repeat for all cards\
        '0' means '10' because fuck you, that's why\
        """
        if not (type(deckline) == unicode):
            raise TypeError('Only unicode line accepted by deck constructor')
        d = []
        l=list(deckline)
        while len(l)>0:
            num = int(l.pop(0))
            suit = l.pop(0)
            d.append(Card(suit, num))
        return d
While PEP 256 recommends using triple double quotes, both forms are usually accepted by other Python interpreters.

Post Reply

Who is online

Users browsing this forum: No registered users