[Python-ideas] Consider having numbers.Real provide __complex__?

2021-01-18 Thread Neil Girdhar
I've been following along various issues in mypy regarding challenges with getting the ABCs in numbers (https://docs.python.org/3/library/numbers.html) working. Currently, there's a lot of clever logic in the functions int, float, and complex. Currently, inheriting from Real doesn't give you __

[Python-ideas] Re: Consider having numbers.Real provide __complex__?

2021-01-18 Thread Mark Dickinson
Inheriting from `numbers.Real` _does_ give you `__complex__`, though: https://github.com/python/cpython/blob/314b8787e0c50985ba708034b84ff5b37a1d47de/Lib/numbers.py#L245-L248 Is it instead `float.__complex__` you're asking for? ___ Python-ideas mailing

[Python-ideas] Re: Consider having numbers.Real provide __complex__?

2021-01-18 Thread Shantanu Jain
Yes, I believe the ask is for `int.__complex__`, `float.__complex__` and `complex.__complex__` ( https://github.com/python/mypy/issues/3186#issuecomment-762121456) On Mon, 18 Jan 2021 at 09:47, Mark Dickinson wrote: > Inheriting from `numbers.Real` _does_ give you `__complex__`, though: > https:

[Python-ideas] Re: pathlib.Path.makedirs

2021-01-18 Thread Random832
On Wed, Jan 13, 2021, at 08:31, Antonio Cavallo wrote: > Hi, > I've found myself typing too many time this: > pathlib.Path("some-dir-name").mkdir(parent=True, exist_ok=True) > > Wouldn't be better to have a pathlib.Path.makedirs with parent/exist_ok > set to True by default? Worth mentioning, th

[Python-ideas] Re: Python with braces formal proposal?

2021-01-18 Thread Random832
On Tue, Jan 5, 2021, at 17:17, lasizoillo wrote: > Sorry, but if I'm understanting the point is to make one-liners. For > example, if I want to do something like: > > $ env | grep "^XDG" > > In one python one liner like > > $ python -c 'import os;print("\n".join([f"{key}:{value}" for key, value

[Python-ideas] Re: Consider having numbers.Real provide __complex__?

2021-01-18 Thread Neil Girdhar
Thanks for the correction Mark, I didn't realize that! Shantanu is right about what my ask was meant to be. I guess I'm nowhere near the first to propose things like this and there's a lot of discussion in various threads about it that I wasn't aware of. Best, Neil On Monday, January 18, 202

[Python-ideas] Re: pathlib enhancements

2021-01-18 Thread Random832
On Fri, Jan 8, 2021, at 15:47, Joseph Martinot-Lagarde wrote: > One remark about this : .tar.gz files are the exception rather than the > rule, and AFAIK maybe the only one ? It's pretty common to have dots in > filenames instead of blanks for example, and stem does the right thing > here : '/da

[Python-ideas] Re: pathlib.Path.makedirs

2021-01-18 Thread Cameron Simpson
On 18Jan2021 16:49, Random832 wrote: >On Wed, Jan 13, 2021, at 08:31, Antonio Cavallo wrote: >> I've found myself typing too many time this: >> pathlib.Path("some-dir-name").mkdir(parent=True, exist_ok=True) >> >> Wouldn't be better to have a pathlib.Path.makedirs with parent/exist_ok >> set to Tr

[Python-ideas] Re: Python with braces formal proposal?

2021-01-18 Thread Chris Angelico
On Tue, Jan 19, 2021 at 8:58 AM Random832 wrote: > > On Tue, Jan 5, 2021, at 17:17, lasizoillo wrote: > > Sorry, but if I'm understanting the point is to make one-liners. For > > example, if I want to do something like: > > > > $ env | grep "^XDG" > > > > In one python one liner like > > > > $ pyt

[Python-ideas] Making TYPE_CHECKING builtin.

2021-01-18 Thread Inada Naoki
Hi, all. I want to write type hints without worrying about runtime overhead. Current best practice is: ``` from __future__ import annotations import typing if typing.TYPE_CHECKING: import xxx # modules used only in type hints. ``` But it would be nice if I can avoid importing even "typing"

[Python-ideas] Re: Making TYPE_CHECKING builtin.

2021-01-18 Thread Brandt Bucher
Doesn't explicitly setting it yourself still work? ``` TYPE_CHECKING = False if TYPE_CHECKING: import xxx # modules used only in type hints. ``` This seems to work for mypy, at least. Even just doing `if False:` works correctly (and is arguably the most efficient at runtime). _

[Python-ideas] Re: Making TYPE_CHECKING builtin.

2021-01-18 Thread Guido van Rossum
That's a mypy-specific hack, not something that's guaranteed by a PEP -- but it works great with mypy! On Mon, Jan 18, 2021 at 4:40 PM Brandt Bucher wrote: > Doesn't explicitly setting it yourself still work? > > ``` > TYPE_CHECKING = False > > if TYPE_CHECKING: > import xxx # modules used

[Python-ideas] Re: Python with braces formal proposal?

2021-01-18 Thread David Mertz
> > what if we had special support for python -c (and maybe in some other > places like exec(), but definitely not for source files) for the purpose of > one-liners? Then the syntax wouldn't need to be suitable for general > purpose use, and you could do something like "have ~{ ~} ~; as alternate >

[Python-ideas] Re: Making TYPE_CHECKING builtin.

2021-01-18 Thread Inada Naoki
Thank you! I didn't know that. I will use `if False: # TYPE_CHECKING` so the compiler will remove all imports inner it. But the official way is preferred so that all typing ecosystems follow it. -- Inada Naoki ___ Python-ideas mailing list -- python

[Python-ideas] Re: Making TYPE_CHECKING builtin.

2021-01-18 Thread Paul Sokolovsky
Hello, On Tue, 19 Jan 2021 08:54:33 +0900 Inada Naoki wrote: > Hi, all. > > I want to write type hints without worrying about runtime overhead. > Current best practice is: > > ``` > from __future__ import annotations > > import typing > > if typing.TYPE_CHECKING: > import xxx # modules u