Ensure PlatformDirs is valid superclass type for mypy AND not an abstract class for other checkers#295
Merged
gaborbernat merged 4 commits intotox-dev:mainfrom Sep 7, 2024
Avasam:Ensure-PlatformDirs-is-valid-superclass-type-for-mypy
Merged
Ensure PlatformDirs is valid superclass type for mypy AND not an abstract class for other checkers#295gaborbernat merged 4 commits intotox-dev:mainfrom Avasam:Ensure-PlatformDirs-is-valid-superclass-type-for-mypy
gaborbernat merged 4 commits intotox-dev:mainfrom
Avasam:Ensure-PlatformDirs-is-valid-superclass-type-for-mypy
Conversation
Contributor
Author
|
The doc test doesn't like Thankfully |
Avasam
commented
Aug 24, 2024
| else: | ||
| from platformdirs.unix import Unix as Result # noqa: PLC0415 | ||
|
|
||
| def _set_platform_dir_class() -> type[PlatformDirsABC]: |
Contributor
Author
There was a problem hiding this comment.
Note that if python/mypy#10962 is fixed, this should become
Suggested change
| def _set_platform_dir_class() -> type[PlatformDirsABC]: | |
| def _set_platform_dir_class() -> type[_Result | Android]: |
But that'd require duplicating the from platformdirs.android import Android import in the TYPE_CHECKING block to keep it a lazy import. And it brings no benefit at the current time.
ldetmer
referenced
this pull request
in googleapis/sdk-platform-java
Sep 9, 2024
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [platformdirs](https://redirect.github.com/platformdirs/platformdirs) | `==4.2.2` -> `==4.3.2` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>platformdirs/platformdirs (platformdirs)</summary> ### [`v4.3.2`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.2) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.3.1...4.3.2) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Use uv as installer by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [https://github.com/tox-dev/platformdirs/pull/300](https://redirect.github.com/tox-dev/platformdirs/pull/300) - Fix multi-path returned from `_path` methods on MacOS by [@​matthewhughes934](https://redirect.github.com/matthewhughes934) in [https://github.com/tox-dev/platformdirs/pull/299](https://redirect.github.com/tox-dev/platformdirs/pull/299) #### New Contributors - [@​matthewhughes934](https://redirect.github.com/matthewhughes934) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/299](https://redirect.github.com/tox-dev/platformdirs/pull/299) **Full Changelog**: tox-dev/platformdirs@4.3.1...4.3.2 ### [`v4.3.1`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.1) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.3.0...4.3.1) <!-- Release notes generated using configuration in .github/release.yml at main --> **Full Changelog**: tox-dev/platformdirs@4.3.0...4.3.1 ### [`v4.3.0`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.0) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.2.2...4.3.0) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Speed up Hatch installation by [@​ofek](https://redirect.github.com/ofek) in [https://github.com/tox-dev/platformdirs/pull/282](https://redirect.github.com/tox-dev/platformdirs/pull/282) - Test with Python 3.13 by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/289](https://redirect.github.com/tox-dev/platformdirs/pull/289) - Test with latest PyPy by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/290](https://redirect.github.com/tox-dev/platformdirs/pull/290) - Use `include-hidden-files: true` to upload coverage artifacts by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/298](https://redirect.github.com/tox-dev/platformdirs/pull/298) - Ensure PlatformDirs is valid superclass type for mypy AND not an abstract class for other checkers by [@​Avasam](https://redirect.github.com/Avasam) in [https://github.com/tox-dev/platformdirs/pull/295](https://redirect.github.com/tox-dev/platformdirs/pull/295) #### New Contributors - [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/289](https://redirect.github.com/tox-dev/platformdirs/pull/289) - [@​Avasam](https://redirect.github.com/Avasam) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/295](https://redirect.github.com/tox-dev/platformdirs/pull/295) **Full Changelog**: tox-dev/platformdirs@4.2.2...4.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/googleapis/sdk-platform-java). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41OS4yIiwidXBkYXRlZEluVmVyIjoiMzguNTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
ldetmer
referenced
this pull request
in googleapis/sdk-platform-java
Sep 17, 2024
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [platformdirs](https://redirect.github.com/platformdirs/platformdirs) | `==4.2.2` -> `==4.3.2` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>platformdirs/platformdirs (platformdirs)</summary> ### [`v4.3.2`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.2) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.3.1...4.3.2) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Use uv as installer by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [https://github.com/tox-dev/platformdirs/pull/300](https://redirect.github.com/tox-dev/platformdirs/pull/300) - Fix multi-path returned from `_path` methods on MacOS by [@​matthewhughes934](https://redirect.github.com/matthewhughes934) in [https://github.com/tox-dev/platformdirs/pull/299](https://redirect.github.com/tox-dev/platformdirs/pull/299) #### New Contributors - [@​matthewhughes934](https://redirect.github.com/matthewhughes934) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/299](https://redirect.github.com/tox-dev/platformdirs/pull/299) **Full Changelog**: tox-dev/platformdirs@4.3.1...4.3.2 ### [`v4.3.1`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.1) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.3.0...4.3.1) <!-- Release notes generated using configuration in .github/release.yml at main --> **Full Changelog**: tox-dev/platformdirs@4.3.0...4.3.1 ### [`v4.3.0`](https://redirect.github.com/tox-dev/platformdirs/releases/tag/4.3.0) [Compare Source](https://redirect.github.com/platformdirs/platformdirs/compare/4.2.2...4.3.0) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Speed up Hatch installation by [@​ofek](https://redirect.github.com/ofek) in [https://github.com/tox-dev/platformdirs/pull/282](https://redirect.github.com/tox-dev/platformdirs/pull/282) - Test with Python 3.13 by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/289](https://redirect.github.com/tox-dev/platformdirs/pull/289) - Test with latest PyPy by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/290](https://redirect.github.com/tox-dev/platformdirs/pull/290) - Use `include-hidden-files: true` to upload coverage artifacts by [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) in [https://github.com/tox-dev/platformdirs/pull/298](https://redirect.github.com/tox-dev/platformdirs/pull/298) - Ensure PlatformDirs is valid superclass type for mypy AND not an abstract class for other checkers by [@​Avasam](https://redirect.github.com/Avasam) in [https://github.com/tox-dev/platformdirs/pull/295](https://redirect.github.com/tox-dev/platformdirs/pull/295) #### New Contributors - [@​edgarrmondragon](https://redirect.github.com/edgarrmondragon) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/289](https://redirect.github.com/tox-dev/platformdirs/pull/289) - [@​Avasam](https://redirect.github.com/Avasam) made their first contribution in [https://github.com/tox-dev/platformdirs/pull/295](https://redirect.github.com/tox-dev/platformdirs/pull/295) **Full Changelog**: tox-dev/platformdirs@4.2.2...4.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/googleapis/sdk-platform-java). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41OS4yIiwidXBkYXRlZEluVmVyIjoiMzguNTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This was spotted in https://github.com/jaraco/jaraco.abode/blob/8843f360ee5d9bc1afb1bdb3119157addb4aaf06/jaraco/abode/config.py#L4C7-L4C19 / jaraco/skeleton#136 (comment)
Trying to subclass
PlatformDirs(and by extension,AppDirs) results in the following error with mypy:Variable "platformdirs.PlatformDirs" is not valid as a typeThis is a known issue: python/mypy#10962
Thankfully it can be worked around, which this PR does, as well as adding a static test for it.
Then another issue is revealed, since
PlatformDirsis typed as being an abstract class, it shouldn't be allowed to be instantiated ! So I can't just do:I'm honnestly a bit dumbofunded by that one. It's a perfect unfixeable storm.
I can't type
PlatformDirsas aTypeAliasoftype[Result] | type[Android]because we're right back to square one.And without https://peps.python.org/pep-0738/ I can't just alias
PlatformDirstoResultotherwiseif PlatformDirs is Androidwill always be raised as an issue by type_checkers. Same if I makePlatformDirsa fake subclass ofPlatformDirsABCin theTYPE_CHECKINGblock.I think the false positive on
if PlatformDirs is Androidis probably much better than a false positive onclass MySubclass(PlatformDirs): ...So I'll go for that.