diff --git a/loguru/__init__.pyi b/loguru/__init__.pyi index 4e20ecb3..f8d8da37 100644 --- a/loguru/__init__.pyi +++ b/loguru/__init__.pyi @@ -176,7 +176,7 @@ class RecordException(NamedTuple): class Record(TypedDict): elapsed: timedelta exception: Optional[RecordException] - extra: dict + extra: Dict[Any, Any] file: RecordFile function: str level: RecordLevel @@ -204,7 +204,7 @@ CompressionFunction = Callable[[str], None] # Actually unusable because TypedDict can't allow extra keys: python/mypy#4617 class _HandlerConfig(TypedDict, total=False): - sink: Union[str, PathLike, TextIO, Writable, Callable[[Message], None], Handler] + sink: Union[str, PathLike[str], TextIO, Writable, Callable[[Message], None], Handler] level: Union[str, int] format: Union[str, FormatFunction] filter: Optional[Union[str, FilterFunction, FilterDict]] @@ -258,7 +258,7 @@ class Logger: @overload def add( self, - sink: Union[str, PathLike], + sink: Union[str, PathLike[str]], *, level: Union[str, int] = ..., format: Union[str, FormatFunction] = ..., @@ -329,19 +329,32 @@ class Logger: *, handlers: Sequence[Dict[str, Any]] = ..., levels: Optional[Sequence[LevelConfig]] = ..., - extra: Optional[dict] = ..., + extra: Optional[Dict[Any, Any]] = ..., patcher: Optional[PatcherFunction] = ..., activation: Optional[Sequence[ActivationConfig]] = ... ) -> List[int]: ... - # @overload should be used to differentiate bytes and str once python/mypy#7781 is fixed - @staticmethod + # @staticmethod cannot be used with @overload in mypy (python/mypy#7781). + # However Logger is not exposed and logger is an instance of Logger + # so for type checkers it is all the same whether it is defined here + # as a static method or an instance method. + @overload def parse( - file: Union[str, PathLike, TextIO, BinaryIO], - pattern: Union[str, bytes, Pattern[str], Pattern[bytes]], + self, + file: Union[str, PathLike[str], TextIO], + pattern: Union[str, Pattern[str]], + *, + cast: Union[Dict[str, Callable[[str], Any]], Callable[[Dict[str, str]], None]] = ..., + chunk: int = ... + ) -> Generator[Dict[str, Any], None, None]: ... + @overload + def parse( + self, + file: BinaryIO, + pattern: Union[bytes, Pattern[bytes]], *, - cast: Union[dict, Callable[[dict], None]] = ..., + cast: Union[Dict[str, Callable[[bytes], Any]], Callable[[Dict[str, bytes]], None]] = ..., chunk: int = ... - ) -> Generator[dict, None, None]: ... + ) -> Generator[Dict[str, Any], None, None]: ... @overload def trace(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... @overload