Documentation question about meta-variables

8 views
Skip to first unread message

Steve Kelem

unread,
May 8, 2020, 10:45:11 PM5/8/20
to pypa-dev
In the documentation on the PyPI page https://docs.pytest.org/en/latest/xunit_setup.html, section "Class level setup/teardown", it says:
@classmethod
def setup_class(cls):
    """ setup any state specific to the execution of the given class (which usually contains tests).
    """
Is "cls" a litteral, like "def", or a placeholder for a given class name? If it's a placeholder, it would be clearer if it were distinguished in some way, such as putting it in italics.

Sviatoslav Sydorenko

unread,
May 9, 2020, 4:45:07 AM5/9/20
to Steve Kelem, pypa-dev
Class is a class itself that is being passed to classmethods. I recommend you to learn how they work to understand better. But essentially naming it cls is a widely used/known convention in the Python ecosystem.


--Sviatoslav.

Sent from my phone, please pardon any typos.

сб, 9 трав. 2020, 04:45 користувач Steve Kelem <steve...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "pypa-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pypa-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pypa-dev/24b4ed40-ea64-4d2c-a68f-50df0ac70a2c%40googlegroups.com.

Sviatoslav Sydorenko

unread,
May 10, 2020, 6:27:22 AM5/10/20
to pypa-dev, Steve Kelem
Hey Steve,

сб, 9 трав. 2020 о 21:56 Steve Kelem <st...@kelem.net> пише:
> Still, I'm not a newbie. I have a PhD in Computer Science, with a minor in programming languages. I have been programming professionally for close to 50 years. I find the typography on the python website unclear, because it's overloaded. In some places, dark-green constant-width fonts mean literals. In other places, it's used for meta-variables.
>

The Sphinx theme is here:
https://github.com/pytest-dev/pytest/tree/master/doc/en/_themes. You
may want to
take a look at the pygments config and see if you can suggest any
coloring changes. It'd probably require an
issue on GitHub to see if the core team will accept your proposal,
followed by a pull request that implements
the changes.


> If the python typographic conventions are widely known, can you show me where they are stated? How can someone who knows computer languages find out these widely-known facts?
>

I meant that *cls* argument name is common for *@classmethod*s, don't
know about the typography but it
probably shouldn't differ from any other variables/arguments.
Sometimes it's also called *class_* or *klass*.

> By the way, I checked my O'Reilly Python books, which I believe are the de facto standards, and there's no "cls" in the indices. The O'Reilly books have a section, Font Conventions, that makes explicit what each font means, and sticks to it in all their books. Even though it's used in all their books, they make sure to document their conventions and use them consistently so that they communicate, unambiguously, to their readers.
>

I feel like we misunderstood each other here. *cls* does not have any
special meaning. It's just a method argument
name and that's it. Also, nobody colors things manually, highlighting
is done automatically by pygments library. You
can customize the colors for the different types of tokens but you
cannot change the semantical meaning of just
one instance of the variable name to look different from other variables.


FWIW here's a few refs to help you figure out how *@classmethod*
decorator works in Python:

* https://www.youtube.com/watch?v=9rKx-8bj-R0
* https://youtu.be/HTLu2DFOdTg?t=1421
* https://stackoverflow.com/a/1669524/595220
* https://realpython.com/instance-class-and-static-methods-demystified/#class-methods
* https://docs.python.org/3/library/functions.html#classmethod


--
Kind regards,

Sviatoslav Sydorenko
email: sviatoslav+/nospam/~@sydorenko.org.ua

---
https://useplaintext.email/
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
---
Reply all
Reply to author
Forward
0 new messages