Docstring Example
This module provides examples of various Python constructs with Google-style docstrings.
It includes examples of a function, a class with methods, an enum, a data class, an abstract class, and a generator function.
AbstractExample
ConcreteExample
Bases: AbstractExample
A concrete implementation of the AbstractExample class.
Source code in examples/docstring_example.py
do_something() -> str
Performs a specific action.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A description of the action performed. |
ExampleClass
A class that demonstrates methods, read-only and read-write attributes.
Source code in examples/docstring_example.py
age: int
property
writable
int: The read-write age attribute.
name: str
property
str: The read-only name attribute.
read_write_attr: str
property
writable
str: A read-write attribute.
__init__(name: str, age: int) -> None
Initializes the ExampleClass with a name and age.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the person. |
required |
age
|
int
|
The age of the person. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If age is negative. |
Source code in examples/docstring_example.py
greet() -> str
Generates a greeting string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A greeting message that includes the name and age. |
ExampleDataClass
dataclass
ExampleEnum
example_function(param1: int, param2: str) -> bool
This function demonstrates a simple example of a function with parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param1
|
int
|
The first parameter, an integer. |
required |
param2
|
str
|
The second parameter, a string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Returns True if param1 is positive, otherwise False. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If param1 is negative. |