[Python-ideas] Re: Proposal: -X importcache to supplement -X importtime for loaded modules

2023-02-14 Thread Inada Naoki
To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/GEISYQ5BXWGKT33RWF77EOSOMMMFUBUS/ > Code of Conduct: http://python.org/psf/code

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-21 Thread Inada Naoki
On Tue, Jun 21, 2022 at 3:49 AM Marco Sulla wrote: > > On Sun, 19 Jun 2022 at 03:06, Inada Naoki wrote: > > FWIW, I had proposed str.iterlines() to fix incompatibility between > > IO.readlines() and str.splitlines(). > > It's a good idea IMHO. In your mind, str.iterlin

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-18 Thread Inada Naoki
SON. Additionally, there are many very fast string algorithms work with UTF-8 written in C or Rust. Python is glue language. Reducing overhead with such libraries is good for Python. For now, my recommendation is using some library written in Cython if it is performance critical. Regards, -- Inad

[Python-ideas] Re: Less is more? Smaller code and data to fit more into the CPU cache?

2022-03-22 Thread Inada Naoki
can not confirm the benefits. We have macro benchmark (pypeformance), but it is still small. Most hot data fits into L2 cache. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-17 Thread Inada Naoki
On Mon, Jan 17, 2022 at 8:49 PM Steven D'Aprano wrote: > > On Mon, Jan 17, 2022 at 08:04:50PM +0900, Inada Naoki wrote: > > > Name lookup is faster than building set in most case. > > So I don't think cost to look name up is important at all. > > But the cost to look

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-17 Thread Inada Naoki
nt efficiency benefit only when: * It is used in the function scope. and, * It can not be optimized by the compiler now. I am not sure how many such usages in stdlib. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-17 Thread Inada Naoki
d write `_TARGETS = frozenset((3, 5, 7, 11, 12, 18, 27, 28, 30, 35, 57, 88))` in global scope and use it as `if n in _TARGETS`. -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-l

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-16 Thread Inada Naoki
So we can estimate how frozenset literal is useful by seeing how frozenset is used. Unless how the literal improve codes is demonstrated, I am -0.5 on new literal only for consistency. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-i

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-05 Thread Inada Naoki
71. PEP 505 can be used for default parameters (e.g. `hi ??= len(a)`) and many other places. I feel it has far better benefit / language complexity ratio. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscri

[Python-ideas] Re: dict_items.__getitem__?

2021-10-04 Thread Inada Naoki
://mail.python.org/archives/list/python-ideas@python.org/thread/QVTGZD6USSC34D4IJG76UPKZRXBBB4MM/ > but not this exact idea. What is difference between your idea and previsous discussion? -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org T

[Python-ideas] Re: dict.sort()?

2021-05-29 Thread Inada Naoki
FWI, this is a previous thread. https://discuss.python.org/t/add-a-dict-sort-method/5747 2021年5月30日(日) 1:57 Marco Sulla : > Since `dict` now is ordered, how about a `sort()` method? > It could have the same signature of list.sort(), with an optional > parameter "by" that can be "keys" or

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread Inada Naoki
ideas. Since its user environment variable, it won't break legacy applications running in a parent account. Does anyone against adding "Enable UTF-8 mode" in the Start menu? -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-10 Thread Inada Naoki
On Wed, Feb 10, 2021 at 8:39 PM Paul Moore wrote: > > On Wed, 10 Feb 2021 at 11:01, Inada Naoki wrote: > > > > On Wed, Feb 10, 2021 at 5:33 PM Paul Moore wrote: > > > > > > So get PYTHONUTF8 added to the environment activate script. That's a > &g

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-10 Thread Inada Naoki
on the same > > machine, but now, in the age of environments, it's still a really bad idea. > > Sure, PYTHONPATH was just an example. Environment variables are how > you configure Python in many ways. I'm asking why UTF-8 mode is so > special it needs a different configuration m

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-09 Thread Inada Naoki
On Wed, Feb 10, 2021 at 6:02 AM Paul Moore wrote: > > On Tue, 9 Feb 2021 at 17:32, Inada Naoki wrote: > > > > On Tue, Feb 9, 2021 at 7:42 PM M.-A. Lemburg wrote: > > > > > > Here's a good blog post about setting env vars on Windows: > > > > &g

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-09 Thread Inada Naoki
figuration via the application and using the registry. > > Perhaps we could have both: an env var to enable UTF-8 mode and > a registry key set by the installer. > I don't want to recommend env vars and registry for conda and portable Python users... -- Inada Naoki __

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-09 Thread Inada Naoki
On Tue, Feb 9, 2021 at 4:53 PM Christopher Barker wrote: > >> >> because UTF-8 mode helps many Windows users but it is not accessible >> enough for Windows users. > > > It's not just accessibility, but discoverability -- Windows users -- and even > more so developers that don't generally use

[Python-ideas] Re: class(obj) could return obj.__class__

2021-02-08 Thread Inada Naoki
n-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/TMFUKID6KMTEAZAS4ILBHSG23GGYNCS4/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- In

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-08 Thread Inada Naoki
On Tue, Feb 9, 2021 at 3:37 PM Christopher Barker wrote: > > On Mon, Feb 8, 2021 at 6:11 PM Inada Naoki wrote: >> >> > >> Unlike Windows, environment variables work very fine for such use cases. > > > Windows has environment variables, doesn't it? > Bu

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-08 Thread Inada Naoki
ronments might need it too. > Unlike Windows, environment variables work very fine for such use cases. On Unix, direnv, dotenv, and maybe more tools are there. It is not only for Python, but for projects. > Which is another good reason that having it b

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-07 Thread Inada Naoki
8 locale by default. There is no guarantee. But if default locale is not UTF-8, I don't think the environment is suited for beginners who learning to Python. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscrib

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-07 Thread Inada Naoki
eason to put a new config file to user profile. If users don't have system privilege, they can still install another Python. Config file in user profile is fragile. If all venvs start using profile directory, it become unmaintainable soon. We can just recommend per-user install for new users. R

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-06 Thread Inada Naoki
hout strong need. Currently, a per-install setting is not possible. So it is the only problem. If adding option to pyvenv.cfg is not make sense, we can add `python.ini` to same place pyvenv.cfg. i.e., directory containing python.exe, or one above directory. -- Inada Naoki __

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-05 Thread Inada Naoki
> > Also am I right to assume that the impact of these changes would only impact > on Windows? > I think we don't have any reason to restrict this for Windows. But since this idea is proposed only for Windows users, only Windows installer will have "Enable UTF-8 mode" op

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-05 Thread Inada Naoki
ile would not help. > But a python.ini could. > python.exe lookup pyvenv.cfg even outside of venv. So we can write utf8mode=1 in pyvenv.cfg even outside of venv. The main limitation is that users can not write config file in install location when Python is installed for system, not for user.

[Python-ideas] Re: Add a couple of options to open()'s mode parameter to deal with common text encodings

2021-02-04 Thread Inada Naoki
On Fri, Feb 5, 2021 at 8:20 AM Ben Rudiak-Gould wrote: > > > It seems as though most of those commenting in the other thread don't > actually use Python on Windows. I do, and I can say it's a royal pain to have > to write open(path, encoding='utf-8') all the time. If you could write >

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-04 Thread Inada Naoki
o edit any file outside the install location. * Easy to clean uninstall * Portable app friendly * One file per environment * Breaking the config file affects only one environment. So I still prefer pyvenv.cfg. -- Inada Naoki ___ Python-ideas maili

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-01 Thread Inada Naoki
On Tue, Feb 2, 2021 at 6:31 AM Barry Scott wrote: > >> On 30 Jan 2021, at 12:05, Inada Naoki wrote: >> >> Where would Python look for a "configuration file like `pyvenv.cfg`" ? >> >> I am not a Windows expert so I am not sure. But I think it should

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-01-30 Thread Inada Naoki
On Sat, Jan 30, 2021 at 3:45 PM Christopher Barker wrote: > > On Thu, Jan 28, 2021 at 4:25 PM Inada Naoki wrote: >> >> > The "real" solution is to change the defaults not to use the system >> > encoding at all -- which, of course, we are moving towards w

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-01-28 Thread Inada Naoki
On Fri, Jan 29, 2021 at 12:54 PM Ben Rudiak-Gould wrote: > > On Wed, Jan 27, 2021 at 11:36 PM Inada Naoki wrote: >> >> * UnicodeDecodeError is raised when trying to open a text file written in >> UTF-8, such as JSON. >> * UnicodeEncodeError is raised when trying to

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-01-28 Thread Inada Naoki
onment. If we have per-environment option, it's easy to recommend users to enable UTF-8 mode. > Maybe this would be a good thing to do once there are Warnings in place? > Do you mean programs only runs on UTF-8 mode warns if UTF-8 mode is not enabled? e.g. ``` if sys.platform == "

[Python-ideas] Make UTF-8 mode more accessible for Windows users.

2021-01-27 Thread Inada Naoki
small tool to allow configuration after installation? * python3 -m utf8mode enable|disable? * Accessible only for CLI user * Add "Enable UTF-8 mode" and "Disable UTF-8 mode" to Start menu? Any ideas are welcome. -- Inada Naoki _

[Python-ideas] Re: Provide UTF-8 version of Python for Windows.

2021-01-26 Thread Inada Naoki
ocess.PIPE encoding in UTF-8 mode. I need to reconsider about stdin/stdout encoding when they are redirected. Maybe, we can use GetConsoleCP() for stdin encoding, and GetConsoleOutputCP() for output encoding. I will write another proposal for it. -- Inada Naoki _

[Python-ideas] Re: Provide UTF-8 version of Python for Windows.

2021-01-26 Thread Inada Naoki
(ANSI version)" will disable the UTF-8 mode by default. User can override the default by `-Xutf8` option and `PYTHONUTF8` environment variable. Does this idea make sense? -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.o

[Python-ideas] Re: Provide UTF-8 version of Python for Windows.

2021-01-25 Thread Inada Naoki
statistics wouldn't be tracked, unless the installer > phones home. Can pip send `locale.getpreferredencoding(False)` to PyPI? If so, we can set `PYTHONUTF8` environment variable from the installer too. Or we can provide small tool to set/unset `PYTHONUTF8` envi

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-25 Thread Inada Naoki
;> >> Maybe, we need to update the tutorial (*) to use `encoding="utf-8"`. > > > Telling people to always add `encoding='utf8'` makes much more sense to me > than introducing a new function and telling them to do that. > Ok, I will not add open_utf8() to PEP 597, and updat

[Python-ideas] Re: Provide UTF-8 version of Python for Windows.

2021-01-25 Thread Inada Naoki
As my understanding, "Fusion manifest for an unpackaged Win32 app" (*) works for non Store Apps too. (*) https://docs.microsoft.com/ja-jp/windows/uwp/design/globalizing/use-utf8-code-page#examples -- Inada Naoki ___ Python-ideas ma

[Python-ideas] Provide UTF-8 version of Python for Windows.

2021-01-25 Thread Inada Naoki
mportant information for us. Of course, there are some downsides: * Windows team needs to maintain more versions. * More divisions for "Python on Windows" environment. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-25 Thread Inada Naoki
ot;b" is not allowed for mode. (*) Another option is to use "utf-8-sig" for reading and "utf-8" for writing. But it has some drawbacks. utf-8-sig has overhead because it is a wrapper implemented in Python. And TextIOWrapper has fast-paths for ut

[Python-ideas] Changing the default text encoding of pathlib

2021-01-24 Thread Inada Naoki
course, we need a regular deprecation period. When encoding is omitted, they emit DeprecationWarning (or EncodingWarning which is a subclass of DeprecationWarning) in three versions (Python 3.10~3.12). How do you think this idea? Should we "change

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Inada Naoki
ommended, and Notepad uses UTF-8 without BOM as default encoding from 1903, UTF-8 with BOM is still used in some cases. For example, Excel reads CSV file with UTF-8 with BOM or legacy encoding. So some CSV files is written with BOM. Regards, -- Inada Naoki _

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Inada Naoki
fun process repeated again. Yes, if we can change the default encoding in 2030, two open functions will become messy. But there is no promise for the change. Without mitigating the pain, we can not change the default encoding forever. Anyway, thank you for your feedback. Two people prefer `encoding="ut

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Inada Naoki
ding or not. Please read the first motivation section in the PEP. https://www.python.org/dev/peps/pep-0597/#using-the-default-encoding-is-a-common-mistake Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Inada Naoki
On Sat, Jan 23, 2021 at 2:43 PM Random832 wrote: > > On Fri, Jan 22, 2021, at 20:34, Inada Naoki wrote: > > * Default encoding is "utf-8". > > it might be worthwhile to be a little more sophisticated than this. > > Notepad itself uses character set detection

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Inada Naoki
ns and multiple deprecation phases), rather > than aiming for a messy goal where people aren't sure which function > to use? > Ultimate goal is make the "utf-8" default. But I don't know when we can change it. So I focus on what we can do in near future (< 5 years, I hope). Re

[Python-ideas] Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-22 Thread Inada Naoki
t;locale"` instead of `encoding=locale.getpreferredencoding(False)` when they need to use locale encoding. We might change more places where the default encoding is used. But it should be done slowly and carefully. --- How do you think about this idea? Is this w

[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-ideas] Making TYPE_CHECKING builtin.

2021-01-18 Thread Inada Naoki
will break existing `from typing import TYPE_CHECKING` codes. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/li

[Python-ideas] Re: asyncio.to_process function, similar to asyncio.to_thread function

2021-01-03 Thread Inada Naoki
lar function for the > ProcessPoolExecutor, e.g. asyncio.to_process? > asyncio.to_thread doesn't use ThreadPoolExecutor. Since thread is cheap, the function create a new thread every time. On the other hand, process is not cheap. That's why the only thread has convenient way to run function in. R

[Python-ideas] Re: Fixing and improving statement caching in sqlite3

2020-12-30 Thread Inada Naoki
d keys are eventually evicted. (behaves like least recently frequently used?) * Minimum overhead for managing keys. So I think a random eviction algorithm is better than LRU. Off topic: Can we add random_cache to functools, like lru_cache? Rega

[Python-ideas] Re: Making "Any" a builtin

2020-11-29 Thread Inada Naoki
in typing.get_type_hints(), instead of adding Any to builtins. As Abdulla said, having both `any` and `Any` in builtins makes Python more confusing. If typing.get_type_hints() is the problem, why don't we changing typing.get_type_hints() behavior?

[Python-ideas] Re: Making "Any" a builtin

2020-11-29 Thread Inada Naoki
Oh, note that Abdulla said: "we can annotate our **functions** with “Any" right away without the extra step." Python 3.9.0 (default, Nov 21 2020, 14:01:55) >>> from __future__ import annotations >>> def foo(a: Any, b: Dict[Any, An

[Python-ideas] Re: Making "Any" a builtin

2020-11-29 Thread Inada Naoki
gt; https://mail.python.org/archives/list/python-ideas@python.org/message/ELI474TKP2OKHP4NW5HOVUPKDPLYE2JP/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: Fwd: Re: Experimenting with dict performance, and an immutable dict

2020-09-22 Thread Inada Naoki
nce critical part of CPython. We should take care of cost/merit ratio always. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/ma

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

2020-09-17 Thread Inada Naoki
for duck-typed language. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived

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

2020-09-17 Thread Inada Naoki
f. They are just shortcut for common cases. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ M

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

2020-09-16 Thread Inada Naoki
"w", encoding="utf-8") as f: return dump(obj, f, **kwargs) def loadf(obj, path, *, **kwargs): with open(path, "rb") as f: return load(f, **kwargs) Regards, -- Inada Naoki ___ Python-ideas mailing l

[Python-ideas] Re: Fwd: Re: Experimenting with dict performance, and an immutable dict

2020-09-16 Thread Inada Naoki
honic. > python -m timeit -n 1 --setup "from uuid import uuid4 ; o = > {str(uuid4()).replace('-', '') : str(uuid4()).replace('-', '') for i > in range(1)} ; it = iter(o) ; key0 = next(it) ; o.pop(key0)" > "dict(o)" > I

[Python-ideas] Re: Fwd: Re: Experimenting with dict performance, and an immutable dict

2020-09-15 Thread Inada Naoki
quot;]*1000))` is 1, not 1000. > 2. Why, in your opinion, no relevant speedup was done? > We have "one big resize" logic in dict_merge already. And I use dummy empty dictkeys for new empty dict. So we don't allocate any temporary, intermediate dict

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

2020-09-13 Thread Inada Naoki
reas it also > configures 'Infinity'. > In case of encoding, we deprecated and ignored it in json.loads since Python 3.1, and removed in 3.9. Users still can load/save JSON with legacy encodings with open() + dump/load. -- Inada Naoki ___ Python-ideas mail

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

2020-09-11 Thread Inada Naoki
rning. So helper functions will save people from this kind of bugs too. [1] In case of `json.load(f)`, we can use binary file instead. [2] https://www.python.org/dev/peps/pep-0597/ Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Inada Naoki
ng is not acceptable for > many use cases). Maybe, OrderedDict can have od.next_item(key) and od.prev_item(key). Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@py

[Python-ideas] Re: Deferred, coalescing, and other very recent reference counting optimization

2020-08-23 Thread Inada Naoki
.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/G2BCHK766Z6ABFEF5KOKC27W4VBNNVSE/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki _

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-08-03 Thread Inada Naoki
On Tue, Aug 4, 2020 at 3:35 AM Christopher Barker wrote: > > On Sat, Aug 1, 2020 at 6:10 PM Inada Naoki wrote: >> >> Repacking is mutation, and mutating dict while iterating it breaks the >> iterator. >> But `d.items()[42]` don't looks like mutation. > > >

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-08-01 Thread Inada Naoki
On Sun, Aug 2, 2020 at 2:34 AM Christopher Barker wrote: > > On Sat, Aug 1, 2020 at 2:28 AM Marco Sulla > wrote: >> >> On Sat, 1 Aug 2020 at 03:00, Inada Naoki wrote: >>> >>> Please teach me if you know any algorithm which has no hole, O(1) &

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-08-01 Thread Inada Naoki
we add some tools to itertools, instead of "itertools recipe"? * `first(iterable, default=None)` -- same to `[first] = iterable`, but return default value instead of ValueError when iterable is empty. * `nth(iterable, n, default=None)` * `consume(iterator, n=None)` Regards, -- Inada

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-31 Thread Inada Naoki
oduce n temporary tuples. * (CPython implementation detail) dict can detect if there is no hole. index access is O(1) if there is no hole. -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-31 Thread Inada Naoki
difficult to notice it is O(n) operation. They just think "Oh Python is fucking slow!". So it is newbie-unfriendly at some point. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email t

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-31 Thread Inada Naoki
gt; islice(dict.keys(), -1, -5) > > Reverse traversal did work in Python 2 but was foregone when making .keys() a > view in Python 3 in order to avoid lulling users into making usually > unnecessary copies. > dict is reversible now. You

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-31 Thread Inada Naoki
nserted in the hashtable. Yes, the array of items has hole. Otherwise, `del d[k]` become `O(n)`, or `del d[k]` won't preserve insertion order. Please teach me if you know any algorithm which has no hole, O(1) deletion, preserving insertion order, and efficient and f

[Python-ideas] Re: Fwd: Re: Experimenting with dict performance, and an immutable dict

2020-07-28 Thread Inada Naoki
on-master -s 'd=dict.fromkeys(range(1000))' -- 'dict(d)' python-master: . 21.5 us +- 0.2 us python: . 4.52 us +- 0.16 us Mean +- std dev: [python-master] 21.5 us +- 0.2 us -> [python] 4.52 us +- 0.16 us: 4.76x faster (-79%) Regard

[Python-ideas] Re: Experimenting with dict performance, and an immutable dict

2020-07-22 Thread Inada Naoki
enchmark.html Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.py

[Python-ideas] Re: Experimenting with dict performance, and an immutable dict

2020-07-21 Thread Inada Naoki
er/frozendict/test/bench.py > I strongly recommend to use pyperf for benchmarking. Otherwise, you will see random performance changes caused by random reasons including ASLR. https://pypi.org/project/pyperf/ https://pyperf.readthedocs.io/en/latest/ Reg

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-11 Thread Inada Naoki
't conflict with another feature, then we > can add it. I believe this is a bad idea. It leads software to be huge, unmaintainable, and unusable. A Relatively high bar must be set for adding a feature to builtin type than adding a third party package on PyPI. Regards, -- Inada Naoki _

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-10 Thread Inada Naoki
from_container(d) 61 >>> choice_from_container(d) 9858 >>> choice_from_container(d.keys()) 2436 >>> choice_from_container(d.items()) (7685, None) -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-10 Thread Inada Naoki
Oh, sorry. I read you did "random pick from dict", but I hadn't read you did "random pick and mutate dict" use case or not. On Fri, Jul 10, 2020 at 3:08 PM Chris Angelico wrote: > > On Fri, Jul 10, 2020 at 4:04 PM Inada Naoki wrote: > > > > On Fri, Jul 10,

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-10 Thread Inada Naoki
nt to benchmark that use case, the benchmark should include time to mutate dict too. Otherwise, performance benefit is exaggerated and no one trusts the benchmark. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscrib

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-09 Thread Inada Naoki
s randam picking part is the bottleneck, micro optimization for this part is not important. That's why the higher level use case is needed to design useful benchmark. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.or

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-09 Thread Inada Naoki
On Thu, Jul 9, 2020 at 12:45 PM Christopher Barker wrote: > > On Wed, Jul 8, 2020 at 7:13 PM Inada Naoki wrote: >> >> I think this comparison is unfair. > > well, benchmarks always lie > >> > d.items()[0]vslist(d.items())[0] >> >

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-08 Thread Inada Naoki
s()) vsrandom.choice(list(d.items())) Should be compared with `random.choice(items_list)` with `items_list = list(d.items())` setup too. -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-07-07 Thread Inada Naoki
order-based __eq__ comparison? It was rejected in this thread. https://mail.python.org/archives/list/python-...@python.org/thread/R2MPDTTMJXAF54SICFSAWPPCCEWAJ7WF/#K3SYX4DER3WAOWGQ4SPKCKXSXLXTIVAQ -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-29 Thread Inada Naoki
tems[i]) sample 2: for i in range(len(d)): do(d.items()[i]) # if dict_items supports index access. sample 1 is O(n) where n = len(d), but sample 2 is O(n^2). By not supporting index access, dict_items prevents to write such inefficient code. -- Inada Naoki _

[Python-ideas] Re: Permanent code objects (less memory, quicker load, less Unix Copy On Write)

2020-06-22 Thread Inada Naoki
On Mon, Jun 22, 2020 at 8:27 PM Barry Scott wrote: > > * New code and pyc format > * pyc has "rodata" segment >* It can be copied into single memory block, or can be mmapped. > * co_code should be aligned at least 2 bytes. > > > Would higher alignment help? malloc is using 8 or 16 byte

[Python-ideas] Re: Permanent code objects (less memory, quicker load, less Unix Copy On Write)

2020-06-22 Thread Inada Naoki
PyROData is deallocated, it munmap or free "rodata" segment. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailm

[Python-ideas] Re: Doc preview in Github PR

2020-06-16 Thread Inada Naoki
JWPKA7B6GRLZHYD/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-i

[Python-ideas] PEP 597 -- Soft deprecation of omitting encoding

2020-05-03 Thread Inada Naoki
packaging.python.org didn't specify encoding to read a README.md (https://github.com/pypa/packaging.python.org/pull/682) [4] json.tool had used locale encoding to read JSON files. ( https://bugs.python.org/issue33684) Copyright <https://www.python.org/dev/peps/pep-0597/#id22> T

[Python-ideas] Re: Allow using the or operator to denote unions in type annotations

2020-03-13 Thread Inada Naoki
On Sat, Mar 14, 2020 at 1:12 PM Inada Naoki wrote: > I'm sorry, I meant (a) looks more consistent with PEP 560. > Sorry again, I meant PEP 585, not PEP 560 as Guido explained already. -- Inada Naoki ___ Python-ideas mailing list -- python

[Python-ideas] Re: Allow using the or operator to denote unions in type annotations

2020-03-13 Thread Inada Naoki
On Sat, Mar 14, 2020 at 11:24 AM Inada Naoki wrote: > [snip] > a) Add `|` to all types. > b) Support it only statically (`from __future__ import annotations`). > [snip] > But (b) seems more consistent with PEP 560. > I'm sorry, I meant (a) looks more consistent with PEP 560

[Python-ideas] Re: Allow using the or operator to denote unions in type annotations

2020-03-13 Thread Inada Naoki
First of all, I am not so happy about typing is increasing Python runtime complexity. TypeScript is the most successful language with gradual typing. It has almost zero-cost about typing. It doesn't make JavaScript runtime complex. I hoped Python goes in same way. But Python went the different

[Python-ideas] Re: List - append

2020-01-18 Thread Inada Naoki
On Sun, Jan 19, 2020 at 2:45 PM Siddharth Prajosh wrote: > > Moreover, shouldn't it work? > How do I add that feature in Python? How you can do it with warus operator. >>> (xs := list(range(10))).append(42) >>> xs [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 42]

[Python-ideas] Re: Recommend UTF-8 mode on Windows

2020-01-14 Thread Inada Naoki
doesn't break Mercurial. But I'm not sure. (Note that Mercurial on Python 3 on Windows is still beta.) Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Recommend UTF-8 mode on Windows

2020-01-11 Thread Inada Naoki
would definitely prefer to have a checkbox to configure "PYTHONUTF8" during > installation rather than requiring it to be done manually, assuming it can be > done safely and effectively across different systems. Not only for the sake > of lowerin

[Python-ideas] Recommend UTF-8 mode on Windows

2020-01-10 Thread Inada Naoki
cfg in the directory same to python.exe) to enable UTF-8 mode. But it may make Python startup process more complex... Regards, [1]: https://docs.microsoft.com/en-us/windows/uwp/design/globalizing/use-utf8-code-page [2]: https://docs.python.org/3/using/windows.html [3]: Currently, Python version

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-03 Thread Inada Naoki
l.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/OYUGN5FOIQGEHS5XJFGHNLQO4AUJMUON/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki ___ Pyth

[Python-ideas] Re: Sets for easy interning(?)

2019-12-02 Thread Inada Naoki
on.org/message/T3Z32DEMWK46EBPULYB4CVI2QF4FS3WJ/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.py

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-24 Thread Inada Naoki
n is very natural to me. But if we use + for dict merging, I think we should add + to set too. Then the set has `.union()`, `|` and `+` for the same behavior. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To uns

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-20 Thread Inada Naoki
+ and +=, and -0 on doing nothing. > If we choose `+`, `+` is now "merging two containers", not just "concatenate two sequences". So it looks very inconsistent that set uses `|` instead of `+`. This inconsistency looks very ugly to me. How do you feel about this? I thi

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-19 Thread Inada Naoki
first, or even remove unbound method from the PEP. Regards, -- Inada Naoki ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-19 Thread Inada Naoki
+ is the common way to merge two containers in some way. Shouldn't we add it to abc? So I think we shouldn't focus just adding `+` to dict. It comes with huge side effect. We should think about general API design of the (esp. builtin) containers. Regards, -- Inada Naoki

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-17 Thread Inada Naoki
.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/W2FCSC3JDA7NUBXAVSTVCUDEGAKWWPTH/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Inada Naoki ___ Python-ideas mailing l

  1   2   >