From 0979257dd7f6eeb941d751d4d1a57910e4da8ba2 Mon Sep 17 00:00:00 2001 From: Parnassius Date: Fri, 7 Jan 2022 12:07:46 +0100 Subject: [PATCH] Use `os.PathLike` for file names --- construct-stubs/core.pyi | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/construct-stubs/core.pyi b/construct-stubs/core.pyi index 73a1f88..a5603ac 100644 --- a/construct-stubs/core.pyi +++ b/construct-stubs/core.pyi @@ -1,5 +1,6 @@ import enum import io +import os import sys import typing as t @@ -25,6 +26,7 @@ from construct.lib import ( # - Higher Kinded Types: https://sobolevn.me/2020/10/higher-kinded-types-in-python StreamType = t.BinaryIO +FilenameType = t.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]] PathType = str ContextKWType = t.Any @@ -97,18 +99,24 @@ class Construct(t.Generic[ParsedType, BuildTypes]): def parse_stream( self, stream: StreamType, **contextkw: ContextKWType ) -> ParsedType: ... - def parse_file(self, filename: str, **contextkw: ContextKWType) -> ParsedType: ... + def parse_file( + self, filename: FilenameType, **contextkw: ContextKWType + ) -> ParsedType: ... def build(self, obj: BuildTypes, **contextkw: ContextKWType) -> bytes: ... def build_stream( self, obj: BuildTypes, stream: StreamType, **contextkw: ContextKWType ) -> bytes: ... def build_file( - self, obj: BuildTypes, filename: str, **contextkw: ContextKWType + self, obj: BuildTypes, filename: FilenameType, **contextkw: ContextKWType ) -> bytes: ... def sizeof(self, **contextkw: ContextKWType) -> int: ... - def compile(self, filename: str = ...) -> Construct[ParsedType, BuildTypes]: ... - def benchmark(self, sampledata: bytes, filename: str = ...) -> str: ... - def export_ksy(self, schemaname: str = ..., filename: str = ...) -> str: ... + def compile( + self, filename: FilenameType = ... + ) -> Construct[ParsedType, BuildTypes]: ... + def benchmark(self, sampledata: bytes, filename: FilenameType = ...) -> str: ... + def export_ksy( + self, schemaname: str = ..., filename: FilenameType = ... + ) -> str: ... def __rtruediv__( self, name: t.Optional[t.AnyStr] ) -> Renamed[ParsedType, BuildTypes]: ...