Skip to content

Use Literal type for attributes with fixed deterministic values (e.g., blood_group) #23

@8figalltimepro

Description

@8figalltimepro

Description:
Some model attributes in pesuacademy-py, such as blood_group, have a fixed set of known deterministic values.
Currently, these are typed as str, which is too generic and does not provide compile-time validation or IDE auto-completion for allowed values. Additionally, during profile parsing (in _ProfilePageHandler._parse_profile_soup), we should validate that the extracted blood_group exactly matches one of the allowed values before storing it.

Proposed Change:

  • Replace str annotations with Literal where applicable.
    Example:
    from typing import Literal
    
    blood_group: Literal["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"]
  • In _ProfilePageHandler._parse_profile_soup, check that the parsed blood_group exactly matches one of the allowed values before assigning it to the model.
  • Review all models for similar attributes and update accordingly.

Benefits:

  • Improves type safety and reduces risk of invalid values.
  • Enhances developer experience with better auto-completion and inline documentation in IDEs.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions