Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing of external APIs #1533

Merged

Conversation

jemrobinson
Copy link
Member

@jemrobinson jemrobinson commented Aug 1, 2023

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).
  • You have marked this pull request as a draft and added '[WIP]' to the title if needed (if you're not yet ready to merge).
  • You have formatted your code using appropriate automated tools (for example ./tests/AutoFormat_Powershell.ps1 -TargetPath <path to file or directory> for Powershell).

⤴️ Summary

Fix typing issues arising from external Azure SDK libraries

🌂 Related issues

n/a

🔬 Tests

Tested locally

@jemrobinson jemrobinson changed the title Tidy interface to Azure API Fix typing of external APIs Aug 1, 2023
@jemrobinson jemrobinson merged commit 188e491 into alan-turing-institute:python-migration Aug 1, 2023
6 checks passed
@JimMadge
Copy link
Member

JimMadge commented Aug 3, 2023

I remember talking about this. Did typing.cast turn out to be the most sensible thing to do (or at least more sensible than ignoring types)?

@jemrobinson
Copy link
Member Author

Possible options (ordered by how much I like them)

  1. Get Microsoft to fix their type hints
  2. Write our own type hints (turns out to be too much work in this case)
  3. Use cast to manually specify the type we know is returned
  4. Ignore type hints

If you'd like to try (1) or (2) then feel free :)

@JimMadge
Copy link
Member

JimMadge commented Aug 3, 2023

Agreed that an upstream fix is probably the real answer.

I wouldn't want to maintain our own type hints for large, third-party libraries just to make mypy pass though. I think casts or ignores are better in that case.

Maybe a rule of thumbs is,

  • typing.cast when you are very confident about the static type
  • ignore when the type is not static or is poorly defined

@jemrobinson jemrobinson deleted the tidy-azure-api branch April 19, 2024 11:00
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.

2 participants