Stephen J. Turnbull wrote:
> I think this is a pretty unconvincing example. While people seem to
> love to hate on regular expressions, it's hard to see how that beats
> def unquote(string: str) -> str:
> m = re.match(r"^(?:"(.*)"|'(.*)'|(?Pvalue3))$", string)
RegEx feels overkill for
Since Python has built-in syntax for interpolated strings, I believe it's a
good area to idea to extend it to pattern matching, like so:
def unquote(string: str) -> str:
match string:
case f'"{value}"':
return value
case f"'{value}'":
Jelle Zijlstra wrote:
> > I like this too. A practical issue is that list[(a, b)] and list[a, b] look
> the same to the compiler, but they would mean very different things. It's
> not obvious how to fix this in a backward-compatible way.
> > I think it looks much cleaner, and if there isn't any
With the recent submission of [PEP 677][1], I was reminded of an idea I had
with function annotation syntax since the very beginning:
why not let me write:
```python
def f() -> tuple[int, str]:
return 42, 'foo'
```
as:
```python
def f() -> (int, str):
return 42, 'foo'
```
Is there
Instead of changing how `reversed()` works, wouldn't a `reversed=True`
property on `enumerate` itself (which checks if the iterable being
reversible) suffice?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
currently in a `dataclasses.dataclass` based class, you can either have it
hashable and completely immutable (using frozen=True and eq=True), or you can
have it hashable but completely mutable (by using unsafe_hash=True)
unsafe_hash provides the convenience of being able to mutate some fields,
Alright, I see why `str.isfloat()` isn't a thing, and having a builtin float
validation function was besides the point anyway. Thanks for the clarifications
:)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
str currently has methods like isdecimal, isnumeric and isdigit, but there
isn't an isfloat check, which could be very handy.
a trivial implementation could be as simple as:
try:
float(self)
return True
except ValueError:
return False