Skip to content

fix: make gplugins.tidy3d importable with gdsfactory 9.x - #770

Merged
joamatab merged 2 commits into
gdsfactory:mainfrom
jackgdsf:fix/tidy3d-modes-pathtype
Aug 31, 2026
Merged

fix: make gplugins.tidy3d importable with gdsfactory 9.x#770
joamatab merged 2 commits into
gdsfactory:mainfrom
jackgdsf:fix/tidy3d-modes-pathtype

Conversation

@jackgdsf

@jackgdsf jackgdsf commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #769

Problem

import gplugins.tidy3d raises at import time on gdsfactory 9.x:

RuntimeError: error checking inheritance of PathType (type: TypeAliasType)

Waveguide is a pydantic.v1.BaseModel, and its cache_path field was annotated with gdsfactory.typings.PathType, which is now a PEP 695 alias (type PathType = str | pathlib.Path). Pydantic v1 cannot introspect TypeAliasType, so field construction blows up and the whole plugin becomes unimportable.

Fix

Spell the union out in the v1 model and drop the now-unused import. The other PathType uses in gplugins/tidy3d/ are plain function annotations, which are never introspected, so they are left alone.

Verification

With gdsfactory 9.49.0 / gplugins 2.1.4, before the change the import raises; after it:

import gplugins.tidy3d as gt
w = gt.modes.Waveguide(
    wavelength=1.31, core_width=0.5, core_thickness=0.22, slab_thickness=0.0,
    core_material="si", clad_material="sio2", grid_resolution=20, overwrite=True,
)
w.n_eff          # [2.71333363+0.j 2.16974811+0.j]
type(w.cache_path)  # pathlib.PosixPath  (str still coerces, None still disables the cache)

pre-commit run --files gplugins/tidy3d/modes.py passes.

Summary by Sourcery

Make the Tidy3D plugin importable with gdsfactory 9.x while preserving Waveguide cache path support.

Bug Fixes:

  • Restore importability of the Tidy3D plugin with gdsfactory 9.x by making its Pydantic model compatible with the newer path type alias behavior.

Chores:

  • Expand lychee URL exclusions for intermittently inaccessible or crawler-blocking external sites.

`Waveguide` is a pydantic v1 model whose `cache_path` field was annotated
with `gdsfactory.typings.PathType`. In gdsfactory 9.x that is a PEP 695
type alias (`type PathType = str | pathlib.Path`), which pydantic v1
cannot introspect, so `import gplugins.tidy3d` raised:

    RuntimeError: error checking inheritance of PathType (type: TypeAliasType)

Spell the union out in the model. Behaviour is unchanged: str, Path and
None all still validate and coerce as before.

Fixes gdsfactory#769

Co-authored-by: Joaquin Matres <4514346+joamatab@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes gplugins.tidy3d import failures with gdsfactory 9.x by avoiding the PEP 695 PathType alias in the Pydantic v1 Waveguide model; function annotations elsewhere remain unchanged.

File-Level Changes

Change Details Files
Replace the gdsfactory PathType alias in the Pydantic v1 model with an explicit union that Pydantic can introspect.
  • Remove the unused PathType import.
  • Annotate cache_path as str
pathlib.Path

Assessment against linked issues

Issue Objective Addressed Explanation
#769 Make gplugins.tidy3d import successfully with gdsfactory 9.x and pydantic v1 by preventing the Waveguide model from exposing the PEP 695 PathType alias to pydantic.
#769 Preserve Waveguide.cache_path behavior, including support for string paths, pathlib.Path values, and None to disable caching.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

pre-commit's lychee hook fails on three links that are reachable in a
browser but refuse automated requests:

- opg.optica.org (Cloudflare) and 10.1364/* DOIs, which redirect there
- www.srim.org, which times out

Same class as the hosts already listed in .github/.lychee.toml. Content
is unchanged; only the checker config.

Co-authored-by: Joaquin Matres <4514346+joamatab@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@joamatab joamatab added the dependencies Pull requests that update a dependency file label Aug 31, 2026
@joamatab
joamatab merged commit 503c28a into gdsfactory:main Aug 31, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gplugins.tidy3d fails to import: pydantic v1 cannot resolve gdsfactory's PEP 695 PathType alias

2 participants