Skip to content

Feature/eng 2423 migrate to pydantic v2#60

Merged
jamie-sgro merged 4 commits into
mainfrom
feature/ENG-2423_migrate_to_pydantic_v2
Nov 24, 2025
Merged

Feature/eng 2423 migrate to pydantic v2#60
jamie-sgro merged 4 commits into
mainfrom
feature/ENG-2423_migrate_to_pydantic_v2

Conversation

@jamie-sgro

Copy link
Copy Markdown
Member

Description

We're upgrading pydantic across the board to V2. This means updating any deprecated syntax from V1

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Next Steps

  • Assign a reviewer based on the code owner document.

  • Once your review is approved, merge and delete the feature branch

On behalf of the Modis Tools Dev Team, thank you for your hard work! ✨

E   TypeError: 'type' object is not subscriptable
@jamie-sgro jamie-sgro marked this pull request as draft November 21, 2025 14:19
@jamie-sgro jamie-sgro marked this pull request as ready for review November 21, 2025 14:19
@jamie-sgro jamie-sgro marked this pull request as draft November 21, 2025 14:21
@jamie-sgro jamie-sgro marked this pull request as ready for review November 21, 2025 14:21
Comment thread modis_tools/models.py
has_transforms: bool
has_variables: bool
orbit_parameters: dict
orbit_parameters: Dict[Any, Any]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for my information: other than being more explicit, is there any benefit to the new typing syntax?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar question:

  • why explicitly type with a typing.Dict instead of just dict? Can you point to where it recommends this in the migration docs
  • is the purpose of Any just a placeholder to show that we haven't explicitly typed it yet? From glancing at the downstream code, we definitely have expectations for what the contents of the lists and dicts are, so I'd recommend we add the explicit typing that either now or in a second step

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I take back my Any comment re: doing it now. Adding in Any lets you get pylance off your back while still retaining a signal to explicitly type things later

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great question. It's a push and pull between supporting python v3.8 and pydantic v2.

  • New pylance/pydantic wants content filling in the type generic (dict/Dict is a generic)
  • The newer dict[...] syntax doesn't play nice with Python versions <3.9 (ref)

@ShengpeiWang ShengpeiWang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes make sense and CICD passed!

@jtanwk jtanwk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code itself looks like it should broadly work, but some open stylistic questions below

Comment thread modis_tools/models.py
has_transforms: bool
has_variables: bool
orbit_parameters: dict
orbit_parameters: Dict[Any, Any]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar question:

  • why explicitly type with a typing.Dict instead of just dict? Can you point to where it recommends this in the migration docs
  • is the purpose of Any just a placeholder to show that we haven't explicitly typed it yet? From glancing at the downstream code, we definitely have expectations for what the contents of the lists and dicts are, so I'd recommend we add the explicit typing that either now or in a second step

Comment thread requirements.txt
@@ -1,5 +1,5 @@
requests==2.*
pydantic==1.*
pydantic==2.*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did we also want to specify >=2.12.4 here (as you wanted to do in rp)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We have external consumers. Given this is a parent node in the dependency DAG, the semver range should be broadly specified

@jamie-sgro jamie-sgro merged commit 84cfc81 into main Nov 24, 2025
3 checks passed
@jamie-sgro jamie-sgro deleted the feature/ENG-2423_migrate_to_pydantic_v2 branch November 24, 2025 09:32
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.

3 participants