[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-24 Thread python-ideas--- via Python-ideas
There's already: for i in range(j): if i > 5: ... else: ... else: ... ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://m

[Python-ideas] Re: Segmentation of string

2019-12-24 Thread python-ideas--- via Python-ideas
Excuse me, ignore my previous post, this is the correct implementation. It works for every iterable: import itertools as itools def segment(it, n=1): if n < 1: raise ValueError(f"Number of segment must be > 0") try: len_it = len(it)

[Python-ideas] Re: Segmentation of string

2019-12-24 Thread python-ideas--- via Python-ideas
import itertools as itools def segment(it, n=1): try: len_it = len(it) it_true = it except TypeError: it_true = tuple(it) len_it = len(it_true) size, rest = divmod(len_it, n) sizes = [size] * n for i in range(rest): sizes[-i] +=

[Python-ideas] Re: Add symlinks option at shutil.move parameters

2019-12-24 Thread python-ideas--- via Python-ideas
Well, I suppose it wants simlink=False. Anyway, why not change the signature of move to def move(src, dst, **kwargs): and change the call of copytree to copytree(src, real_dst, **kwargs) ? ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Re: Throw a TypeError exception if using type annotations (type hints) & the passed arg or return value is the wrong type

2019-12-24 Thread Andrew Barnert via Python-ideas
On Dec 24, 2019, at 05:34, Andrew T wrote: > > This is a feature PHP has had since PHP7 and is what I use all the time with > PHP. It works on a file by file basis (I guess for backward compatibility), a > declare line needs to be at the top of a file `declare(strict_types=1);` If > this line

[Python-ideas] Re: Throw a TypeError exception if using type annotations (type hints) & the passed arg or return value is the wrong type

2019-12-24 Thread Guido van Rossum
You can do this without having to change the language by writing a decorator that enforces the types. The type information is all recoverable from __attributes__. Be aware though that while enforcing types like int or str is easy, enforcing something list List[int] is less obvious -- you probably

[Python-ideas] Throw a TypeError exception if using type annotations (type hints) & the passed arg or return value is the wrong type

2019-12-24 Thread Andrew T
This is a feature PHP has had since PHP7 and is what I use all the time with PHP. It works on a file by file basis (I guess for backward compatibility), a declare line needs to be at the top of a file `declare(strict_types=1);` If this line is at the top of the file, then a TypeError is thrown o