mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +00:00
feat: add Python API type definitions
This commit is contained in:
parent
3436b5eb02
commit
c4a0efae08
10 changed files with 98 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
32
crates/erg_compiler/lib/pystd/compileall.d.er
Normal file
32
crates/erg_compiler/lib/pystd/compileall.d.er
Normal 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
|
||||
10
crates/erg_compiler/lib/pystd/py_compile.d.er
Normal file
10
crates/erg_compiler/lib/pystd/py_compile.d.er
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
.PyCompileError: ClassType
|
||||
|
||||
.compile!: (
|
||||
file: PathLike,
|
||||
cfile := PathLike,
|
||||
dfile := PathLike,
|
||||
doraise := Bool,
|
||||
optimize := Int,
|
||||
quiet := Int,
|
||||
) => Str
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
11
crates/erg_compiler/lib/pystd/struct.d.er
Normal file
11
crates/erg_compiler/lib/pystd/struct.d.er
Normal 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
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
.parse = pyimport "parse"
|
||||
.request = pyimport "request"
|
||||
.response = pyimport "response"
|
||||
.error = pyimport "error"
|
||||
|
|
|
|||
4
crates/erg_compiler/lib/pystd/urllib.d/error.d.er
Normal file
4
crates/erg_compiler/lib/pystd/urllib.d/error.d.er
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.URLError: ClassType
|
||||
.HTTPError: ClassType
|
||||
.HTTPError <: .URLError
|
||||
.ContentTooShortError: ClassType
|
||||
6
crates/erg_compiler/lib/pystd/urllib.d/response.d.er
Normal file
6
crates/erg_compiler/lib/pystd/urllib.d/response.d.er
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
.tempfile = pyimport "tempfile"
|
||||
|
||||
.AddBase = 'addbase': ClassType
|
||||
.AddCloseHook = 'addclosehook': ClassType
|
||||
.AddInfo = 'addinfo': ClassType
|
||||
.AddInfoUrl = 'addinfourl': ClassType
|
||||
11
crates/erg_compiler/lib/pystd/urllib.d/robotparser.d.er
Normal file
11
crates/erg_compiler/lib/pystd/urllib.d/robotparser.d.er
Normal 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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue