[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread Giang Le
Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you. ___ Pytho

[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread Marco Sulla
On Tue, 29 Sep 2020 at 04:39, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2020-09-28 at 23:10:24 -, > Giang Le wrote: > > > I would like to propose an idea for the regular expression module > > re.search(Pattern, Input) to support List[str] input type. > > > So it will return a matched

[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread Giang Hoang Le
Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you. ___ Python-i

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Greg Ewing
On 29/09/20 4:19 pm, Ben Rudiak-Gould wrote: it's worth mentioning that Haskell has tuples of length 0, 2, 3, ..., but no tuples of length 1. Tuples are meant for putting n values where 1 value is expected, and when n=1 you just put the value there. To elaborate on that a bit, the length of a

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-28 Thread Christopher Barker
Sorry if this isn't the right thread -- there's a few now. But for an example of using both positional and keyword index parameters: I maintain a library (gridded) that provides an abstraction over data on various types of grid (in this case generally Oceanographic model output) -- they can be re

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Ben Rudiak-Gould
On Sun, Sep 27, 2020 at 2:18 PM MRAB wrote: > Consider, for example, the use-case of a function that has an optional > parameter and you want a way to know whether an argument has been > provided but None is a valid value that could be passed in. > > Having a singleton such as Missing would be he

[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread 2QdxY4RzWzUUiLuE
On 2020-09-28 at 23:10:24 -, Giang Le wrote: > I would like to propose an idea for the regular expression module > re.search(Pattern, Input) to support List[str] input type. > So it will return a matched object list if the input is a string > list. Otherwise, it will return a normal matched

[Python-ideas] Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread Giang Le
Hi Everyone, I would like to propose an idea for the regular expression module re.search(Pattern, Input) to support List[str] input type. So it will return a matched object list if the input is a string list. Otherwise, it will return a normal matched object, if the input is a normal string Be

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Stefano Borini
On Mon, 28 Sep 2020 at 15:45, Eric Wieser wrote: > > Would another option be to just stop using the tuple-less index in the > presence of new syntax - so by example, I don't think it would be a reliable approach. Now you end up with a "randomly" occurring special case depending on how it's invok

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread MRAB
On 2020-09-28 06:51, Chris Angelico wrote: On Mon, Sep 28, 2020 at 3:33 PM Christopher Barker wrote: As for using an empty tuple, thanks Guido for laying out the logic so succinctly, and it does make it pretty simple that only the one index case is special. Nevertheless, I think most folks ex

[Python-ideas] Re: Improved Error Message for "Unhashable Type"

2020-09-28 Thread Samuel Freilich via Python-ideas
> The code which raises TypeError does not know whether it was called internally by dict or set method or explicitly by hash It's true, but I don't think it would be too hard to preserve some of the context in some of those common cases. In that bug report, I suggested adding an optional parameter

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-28 Thread Wes Turner
https://github.com/python/cpython/blame/master/Lib/unittest/test/testmock/testwith.py#L16 On Mon, Sep 28, 2020 at 12:00 PM Wes Turner wrote: > `my_dict = (json.load(f) with open(filename.json, "r") as f)` > > Would that be called a generator expression / comprehension context > manager? > > htt

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-28 Thread Wes Turner
`my_dict = (json.load(f) with open(filename.json, "r") as f)` Would that be called a generator expression / comprehension context manager? https://docs.python.org/3/reference/datamodel.html#context-managers https://docs.python.org/3/library/contextlib.html PEP 343 added the "with" statement. T

[Python-ideas] Re: Improved Error Message for "Unhashable Type"

2020-09-28 Thread Christopher Barker
On Mon, Sep 28, 2020 at 6:34 AM Samuel Freilich via Python-ideas < python-ideas@python.org> wrote: > The message does not include: > > * The word "hashable" verbatim, which appears in the glossary > * A link to https://docs.python.org/3/glossary.html#term-hashable > That's a pretty good entry tha

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-28 Thread Eric Wieser
This reminds me of a previous proposal I can't remember if I hit the list with, allowing with open(filename.json, "r") as f: my_dict = json.load(f) to be spelt as a single expression: my_dict = (json.load(f) with open(filename.json, "r") as f) Obviously this would be more usefu

[Python-ideas] Re: Adding mixed positional and keyword to PEP 637

2020-09-28 Thread Eric Wieser
I can offer another example where the new syntax is likely to be of use to numpy. We currently have the following as synonyms: ``` np.copyto(a, b, casting='unsafe') a[...] = b ``` Obviously, it would be nice if we could allow other casting rules for `[]` assignment: ``` np.copyto(a, b, casting='s

[Python-ideas] Re: Improved Error Message for "Unhashable Type"

2020-09-28 Thread Serhiy Storchaka
28.09.20 16:31, Samuel Freilich via Python-ideas пише: > The error message for using a mutable sequence as a set item or map key > seems to frequently confuse Python beginners. The current wording is: > {[1, 2, 3]: [4, 5, 6]} > TypeError: unhashable type: 'list' > > The first thing a Google

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Eric Wieser
Would another option be to just stop using the tuple-less index in the presence of new syntax - so by example, ``` SYNTAXINDEX KWARGS d[*[]]() {} d[*[],] () {} d[**{}] () {} d[**{},] () {} d[foo=1] () {'foo': 1} d[foo=1,] () {'foo

[Python-ideas] Improved Error Message for "Unhashable Type"

2020-09-28 Thread Samuel Freilich via Python-ideas
The error message for using a mutable sequence as a set item or map key seems to frequently confuse Python beginners. The current wording is: >>> {[1, 2, 3]: [4, 5, 6]} TypeError: unhashable type: 'list' The first thing a Google search finds for "unhashable type" is ~4k Stack Overflow results lik