summaryrefslogtreecommitdiffstatshomepage
path: root/tests/cpydiff
Commit message (Collapse)AuthorAge
* tests/cpydiff: Remove types_str_endswith.Angus Gratton2025-04-07
| | | | | | | | MicroPython support for this behaviour was added in eb45d97898a. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/cpydiff: Update CPy diff for assign expr in nested comprehensions.Angus Gratton2025-04-07
| | | | | | | | | Since 7c1584aef1 MicroPython matches CPython in most cases, aside from nested comprehensions. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/cpydiff: Remove builtin_next_arg2.py difference.Damien George2025-03-27
| | | | | | | Because 2-arg `next()` is implemented, and now enabled at the basic feature level. Signed-off-by: Damien George <damien@micropython.org>
* all: Upgrade to ruff v0.9.6.Christian Clauss2025-02-25
| | | | Signed-off-by: Christian Clauss <cclauss@me.com>
* tests/cpydiff: Fix test case for modules_json_nonserializable.Jeff Epler2024-11-11
| | | | | | | | | | | | | | | | The test case was producing the following error: Traceback (most recent call last): File "<stdin>", line 12, in <module> UnicodeError: which did not demonstrate the intended difference (this particular non-json-serializable object DID throw an exception! just not TypeError). The updated test uses a byte string with all ASCII bytes inside, which better illustrates the diference. Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/cpydiff: Add diff for overriding __init__.David Lechner2024-07-25
| | | | | | | | This adds a CPython diff that explains why calling `super().__init__()` is required in MicroPython when subclassing a native type (because `__new__` and `__init__` are not separate functions). Signed-off-by: David Lechner <david@pybricks.com>
* py/objint: Fix int.to_bytes() buffer size checks.Angus Gratton2024-06-24
| | | | | | | | | | | | | | | | | | | | | | | | Fixes and improvements to `int.to_bytes()` are: - No longer overflows if byte size is 0 (closes #13041). - Raises OverflowError in any case where number won't fit into byte length (now matches CPython, previously MicroPython would return a truncated bytes object). - Document that `micropython int.to_bytes()` doesn't implement the optional signed kwarg, but will behave as if `signed=True` when the integer is negative (this is the current behaviour). Add tests for this also. Requires changes for small ints, MPZ large ints, and "long long" large ints. Adds a new set of unit tests for ints between 32 and 64 bits to increase coverage of "long long" large ints, which are otherwise untested. Tested on unix port (64 bit small ints, MPZ long ints) and Zephyr STM32WB board (32 bit small ints, long long large ints). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/cpydiff: Remove deque difference test.Damien George2024-06-21
| | | | | | Because `collections.deque` is now a built-in type in MicroPython. Signed-off-by: Damien George <damien@micropython.org>
* py/lexer: Support raw f-strings.Damien George2024-06-06
| | | | | | | | Support for raw str/bytes already exists, and extending that to raw f-strings is easy. It also reduces code size because it eliminates an error message. Signed-off-by: Damien George <damien@micropython.org>
* py/lexer: Support concatenation of adjacent f-strings.Damien George2024-06-06
| | | | | | | This is quite a simple and small change to support concatenation of adjacent f-strings, and improve compatibility with CPython. Signed-off-by: Damien George <damien@micropython.org>
* tests/cpydiff: Add a note about risk of resizing memoryview targets.Angus Gratton2024-04-22
| | | | | | | | This a stop-gap until there is a proper fix for this. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/cpydiff: Add new CPy diff test for class name mangling.Trent Warlaven2024-02-21
| | | | | | | Adds new tests/documentation for missing name mangling for private class members. Signed-off-by: Trent Warlaven <trwbox@gmail.com>
* py/lexer: Allow conversion specifiers in f-strings (e.g. !r).Jared Hancock2023-06-14
| | | | | | | | | | | | | | | | | | | | | | PEP-498 allows for conversion specifiers like !r and !s to convert the expression declared in braces to be passed through repr() and str() respectively. This updates the logic that detects the end of the expression to also stop when it sees "![rs]" that is either at the end of the f-string or before the ":" indicating the start of the format specifier. The "![rs]" is now retained in the format string, whereas previously it stayed on the end of the expression leading to a syntax error. Previously: `f"{x!y:z}"` --> `"{:z}".format(x!y)` Now: `f"{x!y:z}"` --> `"{!y:z}".format(x)` Note that "!a" is not supported by `str.format` as MicroPython has no `ascii()`, but now this will raise the correct error. Updated cpydiff and added tests. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/builtinimport: Remove partially-loaded modules from sys.modules.David Grayson2023-06-05
| | | | | | | | | | | | | | | | | | | Prior to this commit, importing a module that exists but has a syntax error or some other problem that happens at import time would result in a potentially-incomplete module object getting added to sys.modules. Subsequent imports would use that object, resulting in confusing error messages that hide the root cause of the problem. This commit fixes that issue by removing the failed module from sys.modules using the new NLR callback mechanism. Note that it is still important to add the module to sys.modules while the import is happening so that we can support circular imports just like CPython does. Fixes issue #967. Signed-off-by: David Grayson <davidegrayson@gmail.com>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* unix/moduos: Implement 2-arg version of os.getenv().David Lechner2022-12-14
| | | | | | This adds the `default` argument of `os.getenv(key, default=None)`. Signed-off-by: David Lechner <david@pybricks.com>
* tests/cpydiff: Fix formatting of code snippet to use double quotes.Damien George2022-07-29
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/obj: Add support for __float__ and __complex__ functions.Andrew Leech2022-07-25
|
* py/runtime: Allow multiple *args in a function call.David Lechner2022-03-31
| | | | | | | | | | | | | | | | | | | This is a partial implementation of PEP 448 to allow unpacking multiple star args in a function or method call. This is implemented by changing the emitted bytecodes so that both positional args and star args are stored as positional args. A bitmap is added to indicate if an argument at a given position is a positional argument or a star arg. In the generated code, this new bitmap takes the place of the old star arg. It is stored as a small int, so this means only the first N arguments can be star args where N is the number of bits in a small int. The runtime is modified to interpret this new bytecode format while still trying to perform as few memory reallocations as possible. Signed-off-by: David Lechner <david@pybricks.com>
* all: Update Python formatting to latest Black version 22.1.0.Damien George2022-02-02
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/cpydiff: Clarify f-string diffs regarding concatenation.Jim Mussared2021-11-25
| | | | | | Concatenation of any literals (including f-strings) should be avoided. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/lexer: Support nested [] and {} characters within f-string params.Damien George2021-11-25
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py: Implement partial PEP-498 (f-string) support.Jim Mussared2021-08-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements (most of) the PEP-498 spec for f-strings and is based on https://github.com/micropython/micropython/pull/4998 by @klardotsh. It is implemented in the lexer as a syntax translation to `str.format`: f"{a}" --> "{}".format(a) It also supports: f"{a=}" --> "a={}".format(a) This is done by extracting the arguments into a temporary vstr buffer, then after the string has been tokenized, the lexer input queue is saved and the contents of the temporary vstr buffer are injected into the lexer instead. There are four main limitations: - raw f-strings (`fr` or `rf` prefixes) are not supported and will raise `SyntaxError: raw f-strings are not supported`. - literal concatenation of f-strings with adjacent strings will fail "{}" f"{a}" --> "{}{}".format(a) (str.format will incorrectly use the braces from the non-f-string) f"{a}" f"{a}" --> "{}".format(a) "{}".format(a) (cannot concatenate) - PEP-498 requires the full parser to understand the interpolated argument, however because this entirely runs in the lexer it cannot resolve nested braces in expressions like f"{'}'}" - The !r, !s, and !a conversions are not supported. Includes tests and cpydiffs. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/cpydiff/modules_struct_whitespace_in_format: Run black.David Lechner2021-07-06
| | | | | | | This test snuck through without proper formatting and is causing CI for other unrelated changes to fail. Signed-off-by: David Lechner <david@pybricks.com>
* docs/library: Warn that ustruct doesn't handle spaces in format strings.Tom McDermott2021-07-06
| | | | And also add a test to capture the CPython difference.
* tests/cpydiff: Add test for array constructor with overflowing value.Zoltán Vörös2021-06-13
|
* extmod/modurandom: Add error message when getrandbits has bad value.Macarthur Inbody2021-05-30
| | | | | | | | | | | | | | | | | | The random module's getrandbits() method didn't give a proper error message when calling it with a value that was outside of the range of 1-32, which can lead to confusion using this function (which under CPython can accept numbers larger than 32). Now instead of simply giving a ValueError it gives an error message that states that the number of bits is constrained. Also, since the random module's functions getrandbits() and randint() differ from CPython, tests have been added to describe these differences. For getrandbits the relevant documentation is shown and added to the docs. The same is given for randint method so that the information is more easily found. Finally, since the int object lacks the bit_length() method there is a test for that method also to include within the docs, showing the difference to CPython.
* tests/cpydiff: Add test and workaround for function.__module__ attr.Damien George2021-05-16
| | | | | | | | | | MicroPython does not store any reference from a function object to the module it was defined in, but there is a way to use function.__globals__ to indirectly get the module. See issue #7259. Signed-off-by: Damien George <damien@micropython.org>
* py/objarray: Prohibit comparison of mismatching types.stijn2021-05-13
| | | | | | | | | Array equality is defined as each element being equal but to keep code size down MicroPython implements a binary comparison. This can only be used correctly for elements with the same binary layout though so turn it into an NotImplementedError when comparing types for which the binary comparison yielded incorrect results: types with different sizes, and floating point numbers because nan != nan.
* py/objexcept: Support errno attribute on OSError exceptions.Damien George2021-04-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds the errno attribute to exceptions, so code can retrieve errno codes from an OSError using exc.errno. The implementation here simply lets `errno` (and the existing `value`) attributes work on any exception instance (they both alias args[0]). This is for efficiency and to keep code size down. The pros and cons of this are: Pros: - more compatible with CPython, less difference to document and learn - OSError().errno will correctly return None, whereas the current way of doing it via OSError().args[0] will raise an IndexError - it reduces code size on most bare-metal ports (because they already have the errno qstr) - for Python code that uses exc.errno the generated bytecode is 2 bytes smaller and more efficient to execute (compared with exc.args[0]); so bytecode loaded to RAM saves 2 bytes RAM for each use of this attribute, and bytecode that is frozen saves 2 bytes flash/ROM for each use - it's easier/shorter to type, and saves 2 bytes of space in .py files that use it (for each use) Cons: - increases code size by 4-8 bytes on minimal ports that don't already have the `errno` qstr - all exceptions now have .errno and .value attributes (a cpydiff test is added to address this) See also #2407. Signed-off-by: Damien George <damien@micropython.org>
* tests/cpydiff: Add CPy diff test for assignment expression behaviour.Damien George2020-06-16
|
* tests/cpydiff: Add cpydiff test for __all__ used in imported package.Jim Mussared2020-05-02
|
* tests: Format all Python code with black, except tests in basics subdir.David Lechner2020-03-30
| | | | | | | | | | This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
* tests: Move CPy diff test to real test now that subclass equality works.Damien George2020-02-04
| | | | | Testing for equality of subclassed strings now works, thanks to commit 3aab54bf434e7f025a91ea05052f1bac439fad8c
* tests/cpydiff: Add os module environ differences.David Lechner2020-02-04
|
* tests/cpydiff: Add CPy diff-test for using dict.keys() as a set.Damien George2020-01-06
| | | | See issue #5493.
* tests/cpydiff: Fix typo in types_bytes_keywords.py doc comments.clach042019-10-21
|
* tests/cpydiff: Add case for difference in behaviour of bytes.format().Paul Sokolovsky2018-09-26
|
* tests/cpydiff: Remove types_int_tobytesfloat now that it doesn't fail.Damien George2018-05-08
| | | | | | | | | | Commit e269cabe3ed8bed1b7181359febb686edbb748ae added a check that the first argument to the to_bytes() method is an integer, and now uPy follows CPython behaviour and raises a TypeError for this test. Note: CPython checks the argument types before checking the number of arguments, but uPy does it the other way around, so they give different exception messages for this test, but still the same type, a TypeError.
* tests/cpydiff: Remove working cases from types_float_rounding.Damien George2018-05-04
|
* tests/cpydiff: Remove types_str_decodeerror now that it succeeds.Damien George2018-05-04
| | | | | Commit 68c28174d0e0ec3f6b1461aea3a0b6a1b84610bb implemented checking for valid utf-8 data.
* tests/cpydiff: Remove core_function_unpacking now that it succeeds.Damien George2018-05-04
| | | | Commit 1e70fda69fcb4991eb60ed43e610f664ea1319e6 fixes this difference.
* tests/cpydiff: Indent workaround code snippet so it formats correctly.Damien George2018-03-15
|
* tests/cpydiff: Update subclassing Exception case and give work-around.Damien George2017-12-12
|
* tests/cpydiff: Fix markup where "`" (xref) was used instead of "``" (code).Paul Sokolovsky2017-12-03
|
* tests/cpydiff: Add difference-test for second arg of builtin next().Damien George2017-11-28
|
* tests/cpydiff: Add cases for locals() discrepancies.Paul Sokolovsky2017-09-16
| | | | | MicroPython doesn't maintain local symbolic environment, so any feature depending on it won't work as expected.
* tests/cpydiff: Add case for str.ljust/rjust.Paul Sokolovsky2017-07-09
|
* tests/cpydiff/: Improve wording, add more workarounds.Paul Sokolovsky2017-07-09
|
* tests/cpydiff/core_class_supermultiple: Same cause as core_class_mro.Paul Sokolovsky2017-07-09
|