Add pyairtable.models.schema.FieldType enum#444
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a FieldType enum to provide type-safe field type constants for Airtable field types, replacing string literals throughout the codebase. The enum inherits from str to maintain backward compatibility with existing string-based code.
Key Changes
- Added
FieldTypestring enum with all 33 supported Airtable field types - Updated field configuration classes to use
FieldTypeenum values inLiteraltype hints - Migrated
FIELD_TYPES_TO_CLASSESdictionary keys from string literals to enum values
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyairtable/models/schema.py | Defines the new FieldType enum and updates all field configuration type annotations to use it |
| pyairtable/orm/fields.py | Updates the FIELD_TYPES_TO_CLASSES dictionary to use FieldType enum keys instead of string literals |
| pyairtable/orm/generate.py | Replaces hardcoded field type strings with FieldType enum values in type checking logic |
| tests/test_models_schema.py | Adds comprehensive test coverage for the new FieldType enum |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def __repr__(self) -> str: | ||
| return f"FieldType({self.value!r})" |
There was a problem hiding this comment.
[nitpick] The custom __repr__ method is unnecessary. The default Enum.__repr__ already provides a suitable representation (e.g., <FieldType.SINGLE_LINE_TEXT: 'singleLineText'>). Unless there's a specific requirement for this exact format, the default should be sufficient.
| def __repr__(self) -> str: | |
| return f"FieldType({self.value!r})" |
There was a problem hiding this comment.
Nah, I think the existing representation is ugly, and I will have to stare at this all the time. 😁
Fixes #437