Skip to content

PEP 8: naming | replace class_ example because cls is preferred #4253

Open
@templiert

Description

@templiert

Paragraph P1 recommends cls for any variable or argument known to be a class.
Paragraph P2 states that class_ is better than clss.

I think that P2 can mislead users to think that class_ is generally the preferred naming for a class (even if strictly speaking P1 and P2 are not contradictory and mean that cls > class_ > clss).

In P2, I suggest to replace

class_ is better than clss

by

async_ is better than asynk

or, to match the previous enumeration "is preferable to an abbreviation or corrupted spelling"

async_ is better than asnc or asynk

I chose async because of its high use frequency mentioned here.
Other replacement options:

continue_ is better than ctn or kontinue

break_ is better than brk or breac


P1

If your public attribute name collides with a reserved keyword, append a single trailing underscore to your attribute name. This is preferable to an abbreviation or corrupted spelling. (However, notwithstanding this rule, ‘cls’ is the preferred spelling for any variable or argument which is known to be a class, especially the first argument to a class method.)

P2

If a function argument’s name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss.

Activity

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