Skip to content

Add pyairtable.models.schema.FieldType enum#444

Merged
mesozoic merged 1 commit into
gtalarico:mainfrom
mesozoic:field_type_enum
Nov 5, 2025
Merged

Add pyairtable.models.schema.FieldType enum#444
mesozoic merged 1 commit into
gtalarico:mainfrom
mesozoic:field_type_enum

Conversation

@mesozoic
Copy link
Copy Markdown
Collaborator

@mesozoic mesozoic commented Nov 5, 2025

Fixes #437

@mesozoic mesozoic requested a review from Copilot November 5, 2025 06:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FieldType string enum with all 33 supported Airtable field types
  • Updated field configuration classes to use FieldType enum values in Literal type hints
  • Migrated FIELD_TYPES_TO_CLASSES dictionary 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.

Comment on lines +79 to +80
def __repr__(self) -> str:
return f"FieldType({self.value!r})"
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
def __repr__(self) -> str:
return f"FieldType({self.value!r})"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I think the existing representation is ugly, and I will have to stare at this all the time. 😁

@mesozoic mesozoic merged commit f9a0c21 into gtalarico:main Nov 5, 2025
7 checks passed
@mesozoic mesozoic deleted the field_type_enum branch November 5, 2025 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Where can I find constants/literals for valid field types?

2 participants