Commit Graph

10003 Commits

Author SHA1 Message Date
matthieugouel
81a6927081 fix not_impl.py path for black 2021-11-03 17:57:48 +01:00
Jim Fasarakis-Hilliard
b69cfafad8 Merge pull request #3398 from deantvv/os-error-str-2
os: implement os-error-str according to CPython
2021-11-03 16:53:49 +02:00
Jim Fasarakis-Hilliard
9d95ad248b Merge pull request #3396 from OddBloke/oddbloke/exception_module
correctly set __module__ and __name__ for builtin exceptions
2021-11-03 14:48:24 +02:00
Dean Li
db212d80ff os: implement os-error-str according to CPython
As was: "FileNotFoundError: [Errno 2] No such file or directory (os
error 2)"
To be: "FileNotFoundError: [Errno 2] No such file or directory (os
error 2): 'filename' -> 'filename2'"

Reference CPython implementation
```
if (self->filename) {
    if (self->filename2) {
        return PyUnicode_FromFormat("[Errno %S] %S: %R -> %R",
                                    OR_NONE(self->myerrno),
                                    OR_NONE(self->strerror),
                                    self->filename,
                                    self->filename2);
    } else {
        return PyUnicode_FromFormat("[Errno %S] %S: %R",
                                    OR_NONE(self->myerrno),
                                    OR_NONE(self->strerror),
                                    self->filename);
    }
}
if (self->myerrno && self->strerror)
    return PyUnicode_FromFormat("[Errno %S] %S",
                                self->myerrno, self->strerror);
```
2021-11-03 17:30:28 +08:00
Daniel Watkins
42186caade extra_tests: test stdlib exception __module__/__name__ 2021-11-02 18:28:02 -04:00
Daniel Watkins
9dce9bf0b9 correctly set __module__ and __name__ for builtin exceptions
In CPython's PyErr_NewException[0], the dotted "module.name" passed in is
split on that dot: the content before the dot is set as __module__ in
the created exception class, and the content after it is set as
__name__.

This commit mirrors that behaviour, by introducing a `module` argument
to `PyContext.new_class`: if Some("module_name") is passed, it will be
set as `__module__`.  All exception-creating uses of `new_class` are
updated to pass in their module and class names separately.

[0] https://github.com/python/cpython/blob/main/Python/errors.c#L1082-L1087
2021-11-02 18:28:02 -04:00
Jim Fasarakis-Hilliard
612e943c6c Merge pull request #3394 from Snowapril/fix-ga-param-chaining
Fix `GenericAlias` parameter chaining
2021-11-02 23:37:38 +02:00
Jim Fasarakis-Hilliard
0de92bdc45 Merge pull request #3403 from stvsmth/benches-readme-typo
Fix typo in benches readme.
2021-11-02 16:42:55 +02:00
stvsmth
ba6f855a66 Fix typo in benches readme.
Correct the file location of the index.html file.
2021-11-02 08:37:37 -06:00
Jeong YunWon
93ef12e553 Merge pull request #3401 from coolreader18/stdlib-arrayiter
Don't create an intermediate map for rustpython_stdlib::stdlib_inits
2021-11-02 18:12:28 +09:00
Jeong YunWon
d78347e7ea Merge pull request #3390 from OddBloke/oddbloke/format
cformat.rs: fixes to get two test_format.py tests passing
2021-11-02 18:10:08 +09:00
Jeong YunWon
1092f94a75 Merge pull request #3377 from fanninpm/fix-test-posixpath
Fix error and unexpected success in test_posixpath
2021-11-02 18:05:52 +09:00
Jeong YunWon
7b99d13f60 Merge pull request #3050 from RustPython/upd-deps
Run cargo update + upgrade
2021-11-02 17:58:02 +09:00
Noa
a3723462ce Don't create an intermediate map for rustpython_stdlib::stdlib_inits 2021-11-01 22:37:32 -05:00
Noa
5b780e70e6 Skip panicking test 2021-11-01 20:43:46 -05:00
Daniel Watkins
655bfbc6cf cformat.rs: align exception text with CPython
test_format.py doesn't _fail_ if the text is different, but it does emit
a warning: this fixes those warnings.
2021-11-01 21:34:51 -04:00
Daniel Watkins
c5eba15370 test_format: run test_bytes_and_bytearray_format
All the errors have now been addressed.
2021-11-01 21:34:51 -04:00
Daniel Watkins
4d2747e4b8 cformat.rs: reject %c args > 255 when byte formatting
This matches CPython's behaviour.  Thanks to @DimitrisJim for the
improved implementation here.
2021-11-01 21:34:51 -04:00
Daniel Watkins
1ed3a6ca81 cformat.rs: emit correct "not all arguments" errors for byte formatting
Without this, the code would accept `b"eggs" % b"ham"` and `b"eggs" %
bytearray(b"ham")` because it would detect bytes and bytearray as
mappings (which _are_ permitted to have leftover, unprocessed
arguments).
2021-11-01 21:34:51 -04:00
Daniel Watkins
8594a656c7 cformat.rs: s/string/bytes/ in byte formatting error messages 2021-11-01 21:34:51 -04:00
Daniel Watkins
3e19da8331 cformat.rs: implement b'%a'/b'%r' correctly
Unlike strings, b'%a' and b'%r' are equivalent, and they match the '%a'
behaviour of strings, not '%r'.

Thanks to @youknowone for improving this implementation.
2021-11-01 21:34:51 -04:00
Daniel Watkins
dcc0973b03 cformat.rs: handle bytearrays when formatting b'%c' 2021-11-01 21:34:51 -04:00
Daniel Watkins
380653b6cb cformat.rs: implement %a correctly, using builtins::ascii
The repr() of Unicode strings is the Unicode string, so the previous
code was incorrect for that case (at least).
2021-11-01 21:34:51 -04:00
Daniel Watkins
916f39c2b5 cformat.rs: address memory allocation error with %*s / %.*f
The previous code assumed that, after parsing was complete, both the
padding and the precision integers would always be positive: it
therefore cast them to usize unconditionally.  This meant that when a
negative integer was encountered, it would underflow and attempt to
generate a padded string of around usize::MAX, or a float representation
of that precision: unsurprisingly, these fail to allocate.

For simple format strings (e.g. `%-3s`), this works fine: `-` is
detected as a separate token during parsing, so only the positive
integer (3) is passed through.

However, `%*s` expresses "take the first value as the padding integer,
and the second as the string to be padded" (`"%*s" % (-3, ...)` is
analogous to the previous example).  In this codepath, the parsing does
not handle the padding integer, so it can't strip the leading `-`: the
padding integer is negative.  A negative precision can also be given in
similar fashion, with `"%.*f" % (-3, ...)`.

N.B. This commit does not cause the code to produce the correct _output_
for negative padding integers or precisions provided this way, it
addresses only the crash.
2021-11-01 21:32:48 -04:00
Padraic Fanning
1c6851a631 Skip entire test case 2021-11-01 19:40:19 -04:00
Jim Fasarakis-Hilliard
8bfc9049b2 Merge pull request #3395 from Snowapril/time-windows
Time mod additions for Windows
2021-11-02 00:52:11 +02:00
Lee Dogeon
d2a247eeca Correct typo of types manually created (#3397)
* Correct typo of types manually created

* Apply `cargo fmt`
2021-11-01 09:32:19 -05:00
snowapril
e2142e1d07 Remove skip decorator on window test
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-11-01 15:20:55 +09:00
snowapril
ac7bb4bdf4 Add monotonic, perf_counter, get_clock_info for windows
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-11-01 15:20:55 +09:00
Jim Fasarakis-Hilliard
5f158f2c6f Merge pull request #3385 from OddBloke/oddbloke/mknod
stdlib/posix.rs: implement mknod
2021-10-31 23:27:01 +02:00
Daniel Watkins
34950fdd2a stdlib/posix.rs: fix mknod for MacOS
mknod at isn't available in their libc.
2021-10-31 09:10:35 -04:00
Daniel Watkins
156cf6bc86 stdlib/posix.rs: implement mknod 2021-10-31 09:04:56 -04:00
Jim Fasarakis-Hilliard
1442dd69b4 Merge pull request #3393 from devnexen/netbsd_build_fix
netbsd build fix proposal
2021-10-31 13:35:59 +02:00
snowapril
f6c2999f07 remove duplicated extra_test
As this extra_test already covered by `test_parameter_chaining` in
`test_genericalias.py`, remove duplicated test

Signed-off-by: snowapril <sinjihng@gmail.com>
2021-10-31 20:02:10 +09:00
snowapril
73ccb565d0 remove decorators on success tests
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-10-31 20:02:10 +09:00
snowapril
77cd095b59 fix subs_tvars to working on nested GenericAlias
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-10-31 20:02:10 +09:00
snowapril
2e48ba3e17 fix make_parameters in GenericAlias
make_parameters must not push duplicated parameters
as cpython implementation.

See `tuple_add` function of `genericaliasobject.c` in cpython code
https://github.com/python/cpython/blob/main/Objects/genericaliasobject.c#L191

Signed-off-by: snowapril <sinjihng@gmail.com>
2021-10-31 20:02:10 +09:00
Jim Fasarakis-Hilliard
fe1e375a1f Merge pull request #3392 from deantvv/os-error-str
Implement __str__ for OSError
2021-10-31 12:19:23 +02:00
David Carlier
f56514d61b netbsd build fix proposal 2021-10-31 08:41:14 +00:00
Dean Li
d46f5ba7ab Implement __str__ for OSError
In CPython, __str__ and __repr__ for OSError show different results.
This PR try to match this behavior but without the part after the
message (in following example is "'123' -> '456'").

```
In : exc.__repr__()
Out: "FileNotFoundError(2, 'No such file or directory')"

In : exc.__str__()
Out: "[Errno 2] No such file or directory: '123' -> '456'"

In : exc.args
Out: (2, 'No such file or directory')
```
2021-10-31 09:24:18 +08:00
Noa
588247c4a0 Unskip tests 2021-10-30 19:42:35 -05:00
Noa
358ce09b5c Run cargo upgrade 2021-10-30 19:42:35 -05:00
Noa
6ac95d2e7b Run cargo update 2021-10-30 19:33:30 -05:00
Jeong YunWon
859744236e Merge pull request #3391 from deantvv/os-error-refactor
Refactor OSError
2021-10-30 22:40:10 +09:00
Dean Li
a59556ad25 Refactor OSError
Implement `raw_os_error_to_exc_type` to reduce duplication of errno to
exception type.
2021-10-30 17:05:54 +08:00
Jeong YunWon
2ac05aba66 Merge pull request #3381 from DimitrisJim/time_mod
Time mod additions
2021-10-30 15:42:10 +09:00
Jeong YunWon
abd41b54b1 Merge pull request #3383 from DimitrisJim/silence_wasi_warnings
Fix warnings for wasi check.
2021-10-30 15:35:35 +09:00
Jim Fasarakis-Hilliard
a19e87640c Merge pull request #3388 from OddBloke/oddbloke/opener
stdlib/io.rs: align negative-fd-from-opener exception with CPython
2021-10-29 19:33:14 +03:00
Daniel Watkins
1ea93a59d5 stdlib/io.rs: align negative-fd-from-opener exception with CPython 2021-10-28 15:05:55 -04:00
jfh
c6ac24c2f2 Clean up cfgs, handle 32bit timespec creation, skip tests for windows. 2021-10-28 21:42:40 +03:00