The problem is basically that Python packaging usually is a bit fuzzy. That's
why I prefer to have this in there for quite some time to avoid conflicts of
version mismatches between Jedi/Parso.
It seems that upstream has fixed line numbers in some of the expections
in Python 3.10.0rc1, so update the tests accordingly. This means that
test_non_async_in_async() gets the correct line again,
and test_default_except_error_postition() no longer suffers from
the apparent off-by-one problem.
This doesn't fix tests entirely with Python 3.10 but it's a step
forward.
- Add `NodeOrLeaf.dump()` to generate a readable and "round-trippable" dump for a parser tree
- `parso.tree.search_ancestor()` is deprecated, use `NodeOrLeaf.search_ancestor()` instead
- Set up children's parent in `BaseNode.__init__()`
- Add test for `search_ancestor`
- Various small type annotations improvements
bpo-40066: Enum: adjust repr() to show only enum and member name (not value,
nor angle brackets) and str() to show only member name.
https://bugs.python.org/issue40066
Sometimes time moves slowly and strict comparison is not enough:
```
> assert now < node_cache_item.last_used < time.time()
E assert 1614147958.869299 < 1614147958.869299
E + where 1614147958.869299 = <parso.cache._NodeCacheItem object at 0x10456fe80>.last_used
E + and 1614147958.869299 = <built-in function time>()
E + where <built-in function time> = time.time
test/test_cache.py:149: AssertionError
```
In particular, macOS timings can be a bit coarse.
The test failure is from Apple Silicon M1.
- Properly check for starred expression deletion
- Check for starred expressions not in tuple/list/set (when not in assignment)
- Fix a bug that considered starred expression assignment `[*x] = 1` as invalid
- Enhance test cases for valid and invalid `del` statements and starred expressions
* Support named unicode characters in f-strings
Fixes#154
The previous behavior misinterpreted the curly braces as enclosing an
expression. This change does some cursory validation so we can still
get parse errors in the most egregious cases, but does not validate that
the names are actually valid, only that they are name-shaped and have a
chance of being valid.
The character names appear to obey a few rules:
* Case insensitive
* Name characters are `[A-Z0-9 \-]`
* Whitespace before or after is not allowed
* Whitespace in the middle may only be a single space between words
* Dashes may occur at the start or middle of a word
```py
f"\N{A B}" # might be legal
f"\N{a b}" # equivalent to above
f"\N{A B}" # no way
f"\N{ A B }" # no way
f"""\N{A
B}""" # no way
```
For confirming this regex matches all (current) unicode character names:
```py
import re
import sys
import unicodedata
R = re.compile(r"[A-Za-z0-9\-]+(?: [A-Za-z0-9\-]+)*")
for i in range(sys.maxunicode):
try:
name = unicodedata.name(chr(i))
except ValueError:
# Some small values like 0 and 1 have no name, /shrug
continue
m = R.fullmatch(name)
if m is None:
print("FAIL", repr(name))
```
* Improve tests for named unicode escapes