[Python-ideas] Re: PEP Idea: native f-string support as a match pattern

2022-08-13 Thread Tushar Sadhwani
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

[Python-ideas] PEP Idea: native f-string support as a match pattern

2022-08-13 Thread Tushar Sadhwani
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}'":

[Python-ideas] Re: PEP Idea: Better return type annotation syntax

2022-01-16 Thread Tushar Sadhwani
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

[Python-ideas] PEP Idea: Better return type annotation syntax

2022-01-06 Thread Tushar Sadhwani
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

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-06-06 Thread Tushar Sadhwani
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

[Python-ideas] dataclasses to have a way to make hashable fields immutable

2021-03-12 Thread Tushar Sadhwani
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,

[Python-ideas] Re: str.isfloat()

2020-12-28 Thread Tushar Sadhwani
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

[Python-ideas] str.isfloat()

2020-12-27 Thread Tushar Sadhwani
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