Return string that describes a value Parameters ---------- article : str or None A definite or indefinite article. If the article is indefinite (i.e. "a" or "an") the appropriate one will be inferred. Thus, the arguments of ``describe`` can themselves rep
(
article: str | None,
value: Any,
name: str | None = None,
verbose: bool = False,
capital: bool = False,
)
| 7 | |
| 8 | |
| 9 | def describe( |
| 10 | article: str | None, |
| 11 | value: Any, |
| 12 | name: str | None = None, |
| 13 | verbose: bool = False, |
| 14 | capital: bool = False, |
| 15 | ) -> str: |
| 16 | """Return string that describes a value |
| 17 | |
| 18 | Parameters |
| 19 | ---------- |
| 20 | article : str or None |
| 21 | A definite or indefinite article. If the article is |
| 22 | indefinite (i.e. "a" or "an") the appropriate one |
| 23 | will be inferred. Thus, the arguments of ``describe`` |
| 24 | can themselves represent what the resulting string |
| 25 | will actually look like. If None, then no article |
| 26 | will be prepended to the result. For non-articled |
| 27 | description, values that are instances are treated |
| 28 | definitely, while classes are handled indefinitely. |
| 29 | value : any |
| 30 | The value which will be named. |
| 31 | name : str or None (default: None) |
| 32 | Only applies when ``article`` is "the" - this |
| 33 | ``name`` is a definite reference to the value. |
| 34 | By default one will be inferred from the value's |
| 35 | type and repr methods. |
| 36 | verbose : bool (default: False) |
| 37 | Whether the name should be concise or verbose. When |
| 38 | possible, verbose names include the module, and/or |
| 39 | class name where an object was defined. |
| 40 | capital : bool (default: False) |
| 41 | Whether the first letter of the article should |
| 42 | be capitalized or not. By default it is not. |
| 43 | |
| 44 | Examples |
| 45 | -------- |
| 46 | Indefinite description: |
| 47 | |
| 48 | >>> describe("a", object()) |
| 49 | 'an object' |
| 50 | >>> describe("a", object) |
| 51 | 'an object' |
| 52 | >>> describe("a", type(object)) |
| 53 | 'a type' |
| 54 | |
| 55 | Definite description: |
| 56 | |
| 57 | >>> describe("the", object()) |
| 58 | "the object at '...'" |
| 59 | >>> describe("the", object) |
| 60 | 'the object object' |
| 61 | >>> describe("the", type(object)) |
| 62 | 'the type type' |
| 63 | |
| 64 | Definitely named description: |
| 65 | |
| 66 | >>> describe("the", object(), "I made") |
no test coverage detected
searching dependent graphs…