class SectionType
An enumeration class that defines the types of sections that can be added to documents, providing standardized section type identifiers.
/tf/active/vicechatdev/vice_ai/models.py
15 - 20
simple
Purpose
SectionType is an Enum class that provides a controlled vocabulary for categorizing different types of document sections. It ensures type safety and consistency when working with document structures by defining four distinct section types: TEXT for regular text content, HEADER for section headers, CONTENT for general content blocks, and DATA for dedicated data analysis sections. This enumeration is typically used in document management systems, report generators, or content organization tools to classify and handle different section types appropriately.
Source Code
class SectionType(Enum):
"""Types of sections that can be added to documents"""
TEXT = "text"
HEADER = "header"
CONTENT = "content"
DATA = "data" # Dedicated data analysis section type
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Enum | - |
Parameter Details
bases: Inherits from Enum base class, which provides enumeration functionality including member iteration, value access, and name-based lookup
Return Value
Instantiation returns a SectionType enum member. Each member has a 'name' attribute (e.g., 'TEXT') and a 'value' attribute (e.g., 'text'). Accessing members returns the enum instance itself, which can be compared for equality and used in switch-case logic.
Class Interface
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
TEXT |
SectionType | Enum member representing a regular text section with value 'text' | class |
HEADER |
SectionType | Enum member representing a header section with value 'header' | class |
CONTENT |
SectionType | Enum member representing a general content section with value 'content' | class |
DATA |
SectionType | Enum member representing a dedicated data analysis section with value 'data' | class |
name |
str | Inherited property from Enum that returns the member name (e.g., 'TEXT', 'HEADER') | instance |
value |
str | Inherited property from Enum that returns the member value (e.g., 'text', 'header') | instance |
Dependencies
enum
Required Imports
from enum import Enum
Usage Example
from enum import Enum
class SectionType(Enum):
TEXT = "text"
HEADER = "header"
CONTENT = "content"
DATA = "data"
# Access enum members
text_section = SectionType.TEXT
print(text_section.name) # Output: 'TEXT'
print(text_section.value) # Output: 'text'
# Compare enum members
if text_section == SectionType.TEXT:
print("This is a text section")
# Iterate over all section types
for section_type in SectionType:
print(f"{section_type.name}: {section_type.value}")
# Access by value
section = SectionType("header")
print(section) # Output: SectionType.HEADER
# Access by name
section = SectionType['DATA']
print(section.value) # Output: 'data'
# Use in function parameters
def create_section(section_type: SectionType, content: str):
return {"type": section_type.value, "content": content}
section_dict = create_section(SectionType.HEADER, "Introduction")
Best Practices
- Use SectionType members directly rather than string literals to ensure type safety and prevent typos
- Compare enum members using identity (==) or 'is' operator, not by comparing their string values
- When serializing to JSON or databases, use the .value attribute to get the string representation
- When deserializing, use SectionType(value) constructor to convert strings back to enum members
- Do not modify enum members after class definition as they are immutable
- Use SectionType in type hints for function parameters and return values to improve code clarity
- Iterate over all section types using 'for section_type in SectionType' when needed
- Consider using match/case statements (Python 3.10+) or if/elif chains for handling different section types
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DocumentSection 70.9% similar
-
class DocumentSection_v1 69.9% similar
-
class TextSection 67.2% similar
-
class AnalysisType 62.8% similar
-
class DataSourceType 61.1% similar