Closed Avasam closed 3 weeks ago
The doc test doesn't like typing_extensions
import.
WARNING: Failed guarded type import with ModuleNotFoundError("No module named 'typing_extensions'")
I guess that's because it's not installed in whatever doc making environment.
Thankfully TypeAlias
is not needed for this fix, so I'll omit it
This was spotted in https://github.com/jaraco/jaraco.abode/blob/8843f360ee5d9bc1afb1bdb3119157addb4aaf06/jaraco/abode/config.py#L4C7-L4C19 / https://github.com/jaraco/skeleton/pull/136#issuecomment-2303602369
Trying to subclass
PlatformDirs
(and by extension,AppDirs
) results in the following error with mypy:Variable "platformdirs.PlatformDirs" is not valid as a type
This is a known issue: https://github.com/python/mypy/issues/10962Thankfully it can be worked around, which this PR does, as well as adding a static test for it.
Then another issue is revealed, since
PlatformDirs
is 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
PlatformDirs
as aTypeAlias
oftype[Result] | type[Android]
because we're right back to square one. And without https://peps.python.org/pep-0738/ I can't just aliasPlatformDirs
toResult
otherwiseif PlatformDirs is Android
will always be raised as an issue by type_checkers. Same if I makePlatformDirs
a fake subclass ofPlatformDirsABC
in theTYPE_CHECKING
block.I think the false positive on
if PlatformDirs is Android
is probably much better than a false positive onclass MySubclass(PlatformDirs): ...
So I'll go for that.