Skip to content

fix: address Pydantic v2 deprecation warnings in tests/remove trailing whitespace (Pylint C0303)#87

Open
briansumma wants to merge 3 commits intoNorthShoreAutomation:mainfrom
briansumma:fix/pydantic-deprecation-warnings
Open

fix: address Pydantic v2 deprecation warnings in tests/remove trailing whitespace (Pylint C0303)#87
briansumma wants to merge 3 commits intoNorthShoreAutomation:mainfrom
briansumma:fix/pydantic-deprecation-warnings

Conversation

@briansumma
Copy link
Copy Markdown
Contributor

Summary

This PR addresses several deprecation warnings that were appearing in the pytest output:

  1. Pydantic class-based config deprecation:

    • Replaced class Config with model_config = ConfigDict() in the FieldResponse model
    • Updated imports to include ConfigDict from pydantic
  2. Pydantic serializer warnings for Resolution and TimeCode:

    • Added model_validate class methods to properly handle dict inputs
    • Updated field typing in the Keyframe model to accept either model instances or dictionaries
    • Fixed serialization issues for nested objects
  3. create_asset_filesets deprecation warning:

    • Improved the deprecation notice with proper docstring
    • In tests, updated call to use the non-deprecated method directly
  4. Added whitespace cleanup utility:

    • Added remove_trailing_spaces.sh script to clean up trailing whitespace in files
    • Script is cross-platform compatible (works on both Linux and macOS)

Why these changes are needed

These changes eliminate all deprecation warnings from the test output while maintaining backward compatibility. This makes the test output cleaner and prepares the codebase for future Pydantic updates. The whitespace cleanup script helps maintain consistent code formatting.

Testing done

All tests pass with no warnings:

================================================================================================ 134 passed in 0.32s ================================================================================================

Follow-up work

  1. Consider updating all model classes to use Pydantic v2 features consistently
  2. Add type annotations for better code completion in IDEs
  3. Update documentation to reflect Pydantic v2 usage

Notes for reviewer

  • The changes maintain full backward compatibility
  • No functionality changes, only fixing warnings and improving code quality
  • The model_validate methods ensure proper handling of both dict inputs and model instances

- Replace class Config with ConfigDict in FieldResponse model
- Fix serialization warnings in Resolution and TimeCode classes
- Update typing for Resolution and TimeCode fields in Keyframe model
- Improve create_asset_filesets deprecation notice
- Add model_validate method for dict handling in relevant models
- Add shell script to remove trailing whitespace in files

These changes eliminate the following pytest warnings:
- "Support for class-based `config` is deprecated"
- "create_asset_filesets is deprecated"
- "Pydantic serializer warnings"

Part of ongoing maintenance to ensure compatibility with Pydantic v2.
Remove trailing whitespace from multiple files to comply with Pylint rule C0303.
This change improves code quality and readability while maintaining consistent
formatting across the codebase.

Files affected:
- pythonik/specs/collection.py
- pythonik/specs/base.py
- pythonik/specs/files.py
- pythonik/tests/test_assets.py
- pythonik/tests/test_base_url.py
- pythonik/tests/test_metadata.py
- pythonik/models/assets/collections.py

Added script:
- remove_trailing_spaces.sh: Utility to automatically fix trailing whitespace
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.

1 participant