diff --git a/src/stdlib/Builtins.fs b/src/stdlib/Builtins.fs index 4ec2c42..89cffde 100644 --- a/src/stdlib/Builtins.fs +++ b/src/stdlib/Builtins.fs @@ -230,6 +230,22 @@ type IExports = abstract print: obj: obj -> unit + /// Print with custom end string (default is newline) + [] + abstract print: obj: obj * ``end``: string -> unit + + /// Print with custom separator and end string + [] + abstract print: obj: obj * sep: string * ``end``: string -> unit + + /// Print to a file-like object (e.g., sys.stderr) + [] + abstract print: obj: obj * file: TextIOBase -> unit + + /// Print to a file-like object with custom end string + [] + abstract print: obj: obj * ``end``: string * file: TextIOBase -> unit + [] abstract ``open``: file: int * @@ -257,6 +273,55 @@ type IExports = [] let builtins: IExports = nativeOnly +// ============================================================================ +// Python Built-in Exceptions +// https://docs.python.org/3/library/exceptions.html +// ============================================================================ + +// BaseException subclasses (not Exception subclasses) +// These require special handling in try/catch as they don't inherit from Exception + +/// Raised when the user hits the interrupt key (normally Control-C or Delete). +/// Note: Inherits from BaseException, not Exception. +/// https://docs.python.org/3/library/exceptions.html#KeyboardInterrupt +[] +type KeyboardInterrupt() = + inherit exn() + +/// Raised by the sys.exit() function. +/// Note: Inherits from BaseException, not Exception. +/// https://docs.python.org/3/library/exceptions.html#SystemExit +[] +type SystemExit() = + inherit exn() + +/// Raised when a generator or coroutine is closed. +/// Note: Inherits from BaseException, not Exception. +/// https://docs.python.org/3/library/exceptions.html#GeneratorExit +[] +type GeneratorExit() = + inherit exn() + +// Exception subclasses + +/// Raised when a system function returns a system-related error. +/// https://docs.python.org/3/library/exceptions.html#OSError +[] +type OSError() = + inherit exn() + +/// Raised when an operation runs out of memory. +/// https://docs.python.org/3/library/exceptions.html#MemoryError +[] +type MemoryError() = + inherit exn() + +/// Raised when the interpreter finds an internal error. +/// https://docs.python.org/3/library/exceptions.html#SystemError +[] +type SystemError() = + inherit exn() + // NOTE: Below we can add builtins that don't require overloads, and do not // conflict with common F# or .NET functions. If they do we keep them in // `IExports` above. diff --git a/src/stdlib/Sys.fs b/src/stdlib/Sys.fs index 1558e01..317e5b4 100644 --- a/src/stdlib/Sys.fs +++ b/src/stdlib/Sys.fs @@ -2,6 +2,7 @@ module Fable.Python.Sys open Fable.Core +open Fable.Python.Builtins // fsharplint:disable MemberNames @@ -47,6 +48,15 @@ type IExports = abstract version: string /// Python version information as a tuple abstract version_info: VersionInfo + /// Standard input stream + /// See https://docs.python.org/3/library/sys.html#sys.stdin + abstract stdin: TextIOBase + /// Standard output stream + /// See https://docs.python.org/3/library/sys.html#sys.stdout + abstract stdout: TextIOBase + /// Standard error stream + /// See https://docs.python.org/3/library/sys.html#sys.stderr + abstract stderr: TextIOBase /// Exits with code 0, indicating success /// See https://docs.python.org/3/library/sys.html#sys.exit abstract exit: unit -> 'a