mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
importlib.metadata: Improve and test SimplePath protocol (#11436)
Co-authored-by: layday <layday@protonmail.com>
This commit is contained in:
33
test_cases/stdlib/check_importlib_metadata.py
Normal file
33
test_cases/stdlib/check_importlib_metadata.py
Normal 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
|
||||
Reference in New Issue
Block a user