mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-25 19:17:16 +08:00
Improve path-related type hints for setuptools.Extension() and distutils.CCompiler() (#12958)
Co-authored-by: Avasam <samuel.06@hotmail.com>
This commit is contained in:
@@ -1,3 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import distutils.command.sdist
|
||||
from _typeshed import StrPath
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
|
||||
from setuptools._distutils.ccompiler import CCompiler
|
||||
|
||||
c = distutils.command.sdist.sdist
|
||||
|
||||
# Test CCompiler().compile with varied sources
|
||||
|
||||
compiler = CCompiler()
|
||||
|
||||
str_list: list[str] = ["file1.c", "file2.c"]
|
||||
compiler.compile(sources=str_list)
|
||||
|
||||
path_list: list[Path] = [Path("file1.c"), Path("file2.c")]
|
||||
compiler.compile(sources=path_list)
|
||||
|
||||
pathlike_list: list[PathLike[str]] = [Path("file1.c"), Path("file2.c")]
|
||||
compiler.compile(sources=pathlike_list)
|
||||
|
||||
strpath_list: list[StrPath] = [Path("file1.c"), "file2.c"]
|
||||
compiler.compile(sources=strpath_list)
|
||||
|
||||
# Direct literals should also work
|
||||
compiler.compile(sources=["file1.c", "file2.c"])
|
||||
compiler.compile(sources=[Path("file1.c"), Path("file2.c")])
|
||||
compiler.compile(sources=[Path("file1.c"), "file2.c"])
|
||||
|
||||
15
stubs/setuptools/@tests/test_cases/check_extension.py
Normal file
15
stubs/setuptools/@tests/test_cases/check_extension.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
|
||||
from setuptools import Extension
|
||||
|
||||
# Dummy extensions
|
||||
ext1 = Extension(name="test1", sources=["file1.c", "file2.c"]) # plain list[str] works
|
||||
|
||||
path_sources: list[Path] = [Path("file1.c"), Path("file2.c")]
|
||||
ext2 = Extension(name="test2", sources=path_sources) # list of Path(s)
|
||||
|
||||
mixed_sources: list[str | PathLike[str]] = [Path("file1.c"), "file2.c"] # or list[StrPath]
|
||||
ext3 = Extension(name="test3", sources=mixed_sources) # mixed types
|
||||
Reference in New Issue
Block a user