feat: add Python API type definitions

This commit is contained in:
Shunsuke Shibayama 2023-05-03 00:54:05 +09:00
parent 3436b5eb02
commit c4a0efae08
10 changed files with 98 additions and 2 deletions

View file

@ -10,3 +10,18 @@
.Reversible: ClassType
.Genertor: ClassType
.Sequence: ClassType
.MutableSqunce: ClassType
.ByteString: ClassType
.Set: ClassType
.MutableSet: ClassType
.Mapping: ClassType
.MutableMapping: ClassType
.MappingView: ClassType
.ItemsView: ClassType
.KeysView: ClassType
.ValuesView: ClassType
.Awaitable: ClassType
.Coroutine: ClassType
.AsyncIterable: ClassType
.AsyncIterator: ClassType
.AsyncGenerator: ClassType

View file

@ -0,0 +1,32 @@
re = pyimport "re"
.compile_dir!: (
ddir := PathLike,
maxlevels := Nat,
ddir := PathLike,
force := Bool,
rx := re.Pattern or NoneType,
quiet := Int,
legacy := Bool,
optimize := Int,
workers := Nat,
) => Bool
.compile_file!: (
fullname: PathLike,
ddir := PathLike,
force := Bool,
rx := re.Pattern or NoneType,
quiet := Int,
legacy := Bool,
optimize := Int,
) => Bool
.compile_path!: (
skip_curdir := Bool,
maxlevels := Nat,
force := Bool,
quiet := Int,
legacy := Bool,
optimize := Int,
) => Bool

View file

@ -0,0 +1,10 @@
.PyCompileError: ClassType
.compile!: (
file: PathLike,
cfile := PathLike,
dfile := PathLike,
doraise := Bool,
optimize := Int,
quiet := Int,
) => Str

View file

@ -124,7 +124,12 @@
address: (Str, Int) or NoneType := NoneType
) => Int
.socketpair!: (family := Int, type := Int, proto := Int, fileno: Int or NoneType := NoneType) => (.Socket!, .Socket!)
.socketpair!: (
family := Int,
type := Int,
proto := Int,
fileno: Int or NoneType := NoneType
) => (.Socket!, .Socket!)
.create_connection!: (
address: (Str, Int),
timeout: Int or NoneType := NoneType,

View file

@ -0,0 +1,11 @@
.Struct: ClassType
.Struct.
__call__: (format: Str) -> .Struct
format: Str
size: Nat
pack: (self: .Struct, *values: Obj) -> Bytes
unpack: (self: .Struct, bytes: Bytes) -> Obj
.pack: (format: Str, *values: Obj) -> Bytes
.unpack: (format: Str, bytes: Bytes) -> Obj
.calcsize: (format: Str) -> Nat

View file

@ -1,2 +1,4 @@
.parse = pyimport "parse"
.request = pyimport "request"
.response = pyimport "response"
.error = pyimport "error"

View file

@ -0,0 +1,4 @@
.URLError: ClassType
.HTTPError: ClassType
.HTTPError <: .URLError
.ContentTooShortError: ClassType

View file

@ -0,0 +1,6 @@
.tempfile = pyimport "tempfile"
.AddBase = 'addbase': ClassType
.AddCloseHook = 'addclosehook': ClassType
.AddInfo = 'addinfo': ClassType
.AddInfoUrl = 'addinfourl': ClassType

View file

@ -0,0 +1,11 @@
.Entry: ClassType
.Entry.
req_rate: { .requests = Int; .seconds = Int } or NoneType
.RobotFileParser!: ClassType
.RobotFileParser!.
__call__: (url := Str) -> .RobotFileParser!
set_url!: (self: RefMut(.RobotFileParser!), url: Str) => NoneType
read!: (self: RefMut(.RobotFileParser!)) => NoneType
parse!: (self: RefMut(.RobotFileParser!), lines: [Str; _]) => NoneType
request_rate: (self: Ref(.RobotFileParser!), useragent: Str) -> { .requests = Int; .seconds = Int } or NoneType

View file

@ -1680,7 +1680,7 @@ impl Parser {
.map_err(|_| self.stack_dec(fn_name!()))?;
let first_elem = ArgKind::Kw(KwArg::new(keyword, t_spec, rhs));
let tuple = self
.try_reduce_nonempty_tuple(first_elem, false)
.try_reduce_nonempty_tuple(first_elem, self.nth_is(1, Newline))
.map_err(|_| self.stack_dec(fn_name!()))?;
debug_exit_info!(self);
Ok(tuple)