importlib.metadata: Improve and test SimplePath protocol (#11436)

Co-authored-by: layday <layday@protonmail.com>
This commit is contained in:
Jelle Zijlstra
2024-02-18 00:36:01 -08:00
committed by GitHub
parent e961db9492
commit e5d25a7605
6 changed files with 60 additions and 8 deletions

View File

@@ -0,0 +1,33 @@
from __future__ import annotations
import sys
from _typeshed import StrPath
from os import PathLike
from pathlib import Path
from typing import Any
from zipfile import Path as ZipPath
if sys.version_info >= (3, 10):
from importlib.metadata._meta import SimplePath
# Simplified version of zipfile.Path
class MyPath:
@property
def parent(self) -> PathLike[str]: ... # undocumented
def read_text(self, encoding: str | None = ..., errors: str | None = ...) -> str: ...
def joinpath(self, *other: StrPath) -> MyPath: ...
def __truediv__(self, add: StrPath) -> MyPath: ...
if sys.version_info >= (3, 12):
def takes_simple_path(p: SimplePath[Any]) -> None: ...
else:
def takes_simple_path(p: SimplePath) -> None: ...
takes_simple_path(Path())
takes_simple_path(ZipPath(""))
takes_simple_path(MyPath())
takes_simple_path("some string") # type: ignore