[Python-ideas] Re: Pre PEP: Python Literals (was custom strings before)

2021-07-08 Thread Nick Coghlan
On Tue, 6 Jul 2021, 7:56 am Jim Baker, wrote: > > > On Mon, Jul 5, 2021, 2:40 PM Guido van Rossum wrote: > >> FWIW, we could make f-strings properly nest too, like you are proposing >> for backticks. It's just that we'd have to change the lexer. But it would >> not be any harder than would be f

[Python-ideas] Re: Pre PEP: Python Literals (was custom strings before)

2021-07-02 Thread Nick Coghlan
On Fri, 2 Jul 2021, 5:12 pm Thomas Güttler, wrote: > Hi Nick and all other Python ideas friends, > > yes, you are right. There is not much difference between PEP-501 or my > proposal. > > One argument why I would like to prefer backticks: > > Some IDEs detect that you want to use a f-string autom

[Python-ideas] Re: Pre PEP: Python Literals (was custom strings before)

2021-06-26 Thread Nick Coghlan
Stephen J. Turnbull wrote: > But a > PEP 501 i-string "just works" nicely: > load_warning = i'Load is too high: {load}' > while (theres_work_to_do_matey): > if load > max_load: > logging.warn(load_warning) > (This assumes a future version of logging.warn that calls str() on

[Python-ideas] Re: [Python-Dev] Have virtual environments led to neglect of the actual environment?

2021-02-27 Thread Nick Coghlan
bian didn't put the user's local bin directory on the system path by default, so commands provided by user level package installs didn't work without the user adjusting their PATH. The CPython Windows installer also doesn't adjust PATH by default (for good reasons). And unlike a

[Python-ideas] Re: Where should we put the python-ideas HOWTO?

2019-12-03 Thread Nick Coghlan
C. Titus Brown wrote: > put it in the current dev guide somewhere, just so it lands in version > control. > Then iterate on both it and the dev guide. My first thought would be to merge > the content > with this document, > https://github.com/python/devguide/blob/master/langchanges.rst. This op

Re: [Python-ideas] Redefining method

2018-07-30 Thread Nick Coghlan
locality.html and the rest of that site provide some good info on the kinds of problems that "action at a distance" effects, like monkeypatching class definitions, can cause in a code base. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _

Re: [Python-ideas] The future of Python parallelism. The GIL. Subinterpreters. Actors.

2018-07-20 Thread Nick Coghlan
thinking about it further now given a per-interpreter locking model, I suspect there could be some wonderful opportunities for cross-interpreter deadlocks that we didn't consider in our initial design sketch...) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Aust

Re: [Python-ideas] Idea: Deferred Default Arguments?

2018-07-20 Thread Nick Coghlan
that results in name sprawl ("But now I have 15 defaults to export!"), then I take it as a hint that I may not be modeling my data correctly, and am missing a class definition or two somewhere. Cheers, Nick. -- Nick Coghlan | ncogh.

Re: [Python-ideas] Add the imath module

2018-07-14 Thread Nick Coghlan
on the accuracy of student implementations). And in the intmath case, there are likely to be more opportunities to delete private implementations from other standard library modules in favour of the public intmath functions. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, A

Re: [Python-ideas] The future of Python parallelism. The GIL. Subinterpreters. Actors.

2018-07-14 Thread Nick Coghlan
threads that store all persistent state in memory mapped files, or otherwise outside the current process). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail

Re: [Python-ideas] The future of Python parallelism. The GIL. Subinterpreters. Actors.

2018-07-09 Thread Nick Coghlan
protocol that allows for out-of-band data sharing to avoid redundant memory copies: https://www.python.org/dev/peps/pep-0574/ Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Calling python from C completely statically

2018-07-09 Thread Nick Coghlan
the part of the source code responsible for any error messages you're seeing, and try to work out if there's a setting you can tweak to avoid hitting that code path. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___

Re: [Python-ideas] Calling python from C completely statically

2018-07-08 Thread Nick Coghlan
o we support building them as statically linked builtin modules instead (we just don't do it routinely, because we don't have any great desire to make the main executable even larger than it already is). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Nick Coghlan
('Nancy', 'SchoolC'), > ...:] > > In [38]: Grouping(((item[1], item[0]) for item in student_school_list)) > Out[38]: Grouping({'SchoolA': ['Fred', 'Mary'], >'Sc

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Nick Coghlan
mpletely different backend storage model. > But I still think it is much better off as a helper function in itertools. I thought we actually had an open enhancement proposal for adding a "defaultdict.freeze" operation that switched it over to raising KeyError the same way a normal

Re: [Python-ideas] Add a __cite__ method for scientific packages

2018-06-30 Thread Nick Coghlan
tion management support depend on which version of Python you were using seems like it would be mostly a source of pain rather than beneficial. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Nick Coghlan
") >>>> len(tree2.tolist()) 5 Alternatively, you could explore mimicking the way that scikit-learn saves its trained models (which I believe is a variation on "use pickle", but I've never actually gone and checked for sure). Cheers, Nick. -- Nick Coghlan

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-22 Thread Nick Coghlan
lass instances and the behaviour of class methods on classes themselves. So I don't think this is a huge gain in expressiveness, but I do think it's a low cost consistency improvement that should make it easier to start unifying more of the descriptor

Re: [Python-ideas] POPT (Python Ob ject Provider Threads)

2018-06-20 Thread Nick Coghlan
n that front :) (While object creation overhead certainly isn't trivial, the interpreter's already pretty aggressive about repurposing previously allocated and initialised memory for new instances) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Bri

Re: [Python-ideas] Meta-PEP about C functions

2018-06-17 Thread Nick Coghlan
you publish the first draft of your CCall protocol PEP, so that the two PEPs get assigned consecutive numbers (it doesn't really matter if they're non-consecutive, but at the same time, I don't think there's any specific urgency in getting this one published before the CCa

Re: [Python-ideas] Loosen 'as' assignment

2018-06-16 Thread Nick Coghlan
already do that today as: >>> import psycopg2 as pg >>> import psycopg2.extensions >>> pg.ex = pg.extensions Monkeypatching other modules at runtime is a questionable enough practice that we're unlikely to add syntax that actively encoura

Re: [Python-ideas] Link accepted PEPs to their whatsnew section?

2018-06-13 Thread Nick Coghlan
ent idea to me (and may actually help the What's New section supplant the PEP in search results). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://ma

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-11 Thread Nick Coghlan
foundered. PEP 572 arose from Chris deciding to take on the challenge of seriously asking the question "Well, what if we *did* allow capturing of arbitrary subexpressions with inline assignments?". Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _

Re: [Python-ideas] Add hooks to asyncio lifecycle

2018-06-09 Thread Nick Coghlan
to close that loophole, the application should already have the ability to enforce everything else that it wants to enforce via the existing event loop and event loop policy APIs. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia

Re: [Python-ideas] Allow callable in slices

2018-06-09 Thread Nick Coghlan
>>> class MyContainer: ... def __getitem__(self, key): ... return key ... >>> mc = MyContainer() >>> mc[:bool] slice(None, , None) >>> mc[bool:] slice(, None, None) >>> mc[list:tuple:range] slice(, , ) It's onl

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Nick Coghlan
out the code you're currently looking at (if anything, we've been pushing more in the other direction: encouraging the use of features like checked type hints to better *enable* reasoning locally about a piece of code). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com |

Re: [Python-ideas] Let try-except check the exception instance

2018-05-31 Thread Nick Coghlan
xception handlers, although that still sticks to the principle that exception handler checks solely consider the exception type, not its value: https://bugs.python.org/issue12029 -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python

Re: [Python-ideas] Add shutil.chown(..., recursive=False)

2018-05-30 Thread Nick Coghlan
ortability challenges arising from expecting the chown and chmod commands to be available. Cheers, Nick. [1] os.chown and shutil.chown don't exist at all there, and os.chmod only supports setting a file to read-only - there isn't any access to user o

Re: [Python-ideas] Was `os.errno` undocumented?

2018-05-29 Thread Nick Coghlan
ot; section of the What's New guide, with the fix being to switch to "import errno" in any affected code. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.

Re: [Python-ideas] Add shutil.chown(..., recursive=False)

2018-05-29 Thread Nick Coghlan
e state of the disk. shutil.rmtree fortunately provides some good precedent there, but it does mean this feature would need to be implemented as its own API, rather than as an option on shutil.chown. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-05-28 Thread Nick Coghlan
On 28 May 2018 at 10:17, Greg Ewing wrote: > Nick Coghlan wrote: > >> Aye, while I still don't want comprehensions to implicitly create new >> locals in their parent scope, I've come around on the utility of letting >> inline assignment targets be implicitly

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-05-27 Thread Nick Coghlan
; parens are needed, so > added 'em anyway to make grouping clear. > I think the parens would technically be optional (as in PEP 572), since "EXPR for" isn't legal syntax outside parentheses/brackets/braces, so the parser would terminate the assignment expression when it see

Re: [Python-ideas] Meta-PEP about built-in functions

2018-05-23 Thread Nick Coghlan
on what they're proposing to change and why, without each needing to include all the background details regarding the specifics of the current situation. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-

Re: [Python-ideas] Modern language design survey for "assign and compare" statements

2018-05-18 Thread Nick Coghlan
; > But how are newer languages solving the problem today? Believe Ryan > brought > this up first on the list, but it had been in the back of my mind as well. > Finally have compiled my research, corrections welcome. Thank you for compiling this! It's a very useful point of referen

Re: [Python-ideas] Make keywords KEYwords only in places they would have syntactical meaning

2018-05-18 Thread Nick Coghlan
ntroduce a coroutine, and "await EXPR" was only permitted inside coroutine definitions). We also run into the problem that even when the compiler can tell the difference, *humans* are still likely to be confused by the potential ambiguity (for the same reas

Re: [Python-ideas] Escaped braces in format specifiers

2018-05-17 Thread Nick Coghlan
r recursive format > specs. There's no mechanism for having braces that aren't inspected by the > f-string machinery. https://www.python.org/dev/peps/pep-0536/ also seems worth noting (I don't actually understand the specifics of that PEP myself, just making sure tha

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-17 Thread Nick Coghlan
outer scopes. By contrast, if the implicit access to outer scopes is limited to inline scopes accessing their containing scope, then this example becomes precisely analagous to the current syntax error for binding a name as a local before declaring it as global or nonlocal. The statement of ambiguity would arise from the fact that when we see "TARGET := EXPR" at statement level, we don't know if the missing prior statement is a local variable assignment, a type declaration, or a global or nonlocal declaration) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] "given" vs ":=" in list comprehensions

2018-05-14 Thread Nick Coghlan
On 14 May 2018 at 08:24, Ed Kellett wrote: > On 2018-05-14 05:02, Nick Coghlan wrote: > > The same grammar adjustment that I believe will allow "given" to be used > as > > both a postfix keyword and as a regular name would also work for "where". > &g

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-14 Thread Nick Coghlan
#x27;s rejection of the idea of using "NAME := EXPR" to imply "nonlocal NAME" at function scope, but that's effectively on the table for implicit functions anyway (and I'd prefer to have ":=" be consistent everywhere, rather than having to special case the impl

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-13 Thread Nick Coghlan
On 11 May 2018 at 12:45, Tim Peters wrote: > [Nick Coghlan] > > I've been thinking about this problem, and I think for the If/elif/while > > cases it's actually possible to allow the "binding is the same as the > > condition" case to be simplified to

Re: [Python-ideas] Crazy idea: allow keywords as names in certain positions

2018-05-13 Thread Nick Coghlan
I do like the idea of separating out "postfix keywords", which can't start a statement or expression, and hence can be used *unambiguously* as names everywhere that names are allowed. Adding such a capability is essential to proposing a keyword based approach to inline assignment

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-13 Thread Nick Coghlan
in the containing block, > where it inherits that block's `global` or `nonlocal` declaration if > one exists, else establishes that the target is local to that block. > """ > This is getting pretty close to being precise enough to be at least potentially implementa

Re: [Python-ideas] "given" vs ":=" in list comprehensions

2018-05-13 Thread Nick Coghlan
irectly than would be the case for assignment expressions) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-13 Thread Nick Coghlan
o with nested comprehensions, how to expand comprehensions using this kind of scoping to their statement form in a context independent way). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-11 Thread Nick Coghlan
could be made to conditional expressions (adjusting their grammar to permit "EXPR if NAME = EXPR else EXPR") and filter clauses in comprehensions (allowing "EXPR for TARGET in EXPR if NAME = EXPR"). In essence, "if", "elif", and "while" would all

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-11 Thread Nick Coghlan
On 11 May 2018 at 07:15, Nick Coghlan wrote: > * *maybe* discover that even the above expansion isn't quite accurate, and > that the underlying semantic equivalent is actually this (one way to > discover this by accident is to have a name error in the outermost iterabl

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-11 Thread Nick Coghlan
; compiler declaration to explicitly request those semantics for bound names (allowing the expansions of comprehensions and generator expressions as explicitly nested functions to be adjusted accordingly). But the PEP will need to state explicitly that that's what it is doing, and fully specify

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-10 Thread Nick Coghlan
nd name shadowing without explicit name aliasing and del statements), it's something else entirely to do it for the sake of purely cosmetic tweaks like flattening the occasional nested if-else chain or replacing a loop-and-a-half with an embedded assignment. Regards, Nick. -- Nick Coghlan

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-10 Thread Nick Coghlan
On 10 May 2018 at 23:22, Guido van Rossum wrote: > On Thu, May 10, 2018 at 5:17 AM, Nick Coghlan wrote: > >> How would you expect this to work in cases where the generator expression >> isn't immediately consumed? If "p" is nonlocal (or global) by default, then

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-10 Thread Nick Coghlan
resting_coords = [x, y for x in related_x_coord(x, y) if is_interesting(y := f(x))] Deliberately reintroducing stateful side effects into a nominally functional construct seems like a recipe for significant confusion, even if there are some cases where it might arguably be useful to folks th

Re: [Python-ideas] PEP 572: about the operator precedence of :=

2018-05-10 Thread Nick Coghlan
e bound name at least once, you gain a much clearer order of execution (while it's an order of execution that's right-to-left rather than left-to-right, "rightmost expression first" is the normal way assignments get evaluated anyway). Cheers, Nick. -- Nick Coghlan | ncogh...

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-10 Thread Nick Coghlan
zation discusses the "logging.isEnabledFor" API, and how it can be used to avoid the overhead of expensive state queries when the result log message would just be discarded anyway. Generally speaking though, the spelling for that kind of lazy evaluation is to accept a zero-argument call

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-10 Thread Nick Coghlan
. global x ... nonlocal x ... x = 1 ... File "", line 2 SyntaxError: name 'x' is nonlocal and global Since using a name as a binding target *and* as the iteration variable would effectively be declaring it as both local and non

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-10 Thread Nick Coghlan
treatment where it could be allowed as a variable name in a non-operator context (since we don't allow two adjacent expressions to imply a function call, it's only prefix keywords that have to be disallowed as names to avoid ambiguity in the parser). Cheers, Nick. -- Nick Coghlan

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-07 Thread Nick Coghlan
stion is a `pathlib.Path` instance). Your original point is still valid though: given the boilerplate reduction already available via "from pathlib import Path; _this_dir = Path(__file__).parent", it's the pathlib version that needs to be taken as the baseline

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-07 Thread Nick Coghlan
erhead, it doesn't remove it. > That's fine - it's not uncommon for folks looking to minimise startup overhead to have to opt in to using a lower level API for exactly that reason. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 14:33, Nathaniel Smith wrote: > On Sun, May 6, 2018 at 8:47 PM, Nick Coghlan wrote: > > On 7 May 2018 at 13:33, Nathaniel Smith wrote: > >> > >> Spit-balling: how about __filepath__ as a > >> lazily-created-on-first-access pathlib.Path(__

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
nce 6.5 of those milliseconds are from importing fnmatch), I think there's also a legitimate argument for a two tier system here, where we say "If you can't handle your filesystem manipulation task with just open, dirname, abspath, and joinpath, then reach for the higher level pathli

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Nick Coghlan
as nonlocal in the nested scope, so our rem and p point to the last bound value I don't really like that though, since it doesn't read as nicely as being able to put the nonlocal declaration inline. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia __

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 12:35, Chris Angelico wrote: > On Mon, May 7, 2018 at 12:13 PM, Nick Coghlan wrote: > > So I have a different suggestion: perhaps it might make sense to propose > > promoting a key handful of path manipulation operations to the status of > > being builtins?

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 12:51, Nick Coghlan wrote: > If any other form of comprehension level name binding does eventually get > accepted, then inline scope declarations could similarly be used to hoist > values out into the surrounding scope: > > rem = None > while

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Nick Coghlan
into the surrounding scope: rem = None while any((nonlocal rem := n % p) for nonlocal p in small_primes): # p and rem were declared as nonlocal in the nested scope, so our rem and p point to the last bound value Cheers, Nick. -- Nick Coghlan |

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
x27;d still need to import pathlib or os.path for more complex path manipulations, but they generally wouldn't be needed any more if all you're doing is reading and/or writing a handful of specific files. Cheers, Nick. [1] abspath can stand in for os.getcwd(), since you can spell the latter

Re: [Python-ideas] Python-ideas Digest, Vol 138, Issue 32

2018-05-05 Thread Nick Coghlan
indirectly, as in the hypothesis API usage), which is exactly the meaning we're interested in here. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-05 Thread Nick Coghlan
On 6 May 2018 at 02:06, Nick Coghlan wrote: > On 4 May 2018 at 22:06, Nick Coghlan wrote: > >> (Note: Guido's already told me off-list that he doesn't like the way this >> spelling reads, but I wanted to share it anyway since it addresses one of >> the

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-05 Thread Nick Coghlan
On 4 May 2018 at 22:06, Nick Coghlan wrote: > (Note: Guido's already told me off-list that he doesn't like the way this > spelling reads, but I wanted to share it anyway since it addresses one of > the recurring requests in the PEP 572 discussions for a more targeted >

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-05 Thread Nick Coghlan
On 5 May 2018 at 13:36, Tim Peters wrote: > [Nick Coghlan ] > > ... > > The essence of the given clause concept would be to modify *these > specific > > cases* (at least initially) to allow the condition expression to be > followed > > by an inline assignment,

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-05 Thread Nick Coghlan
assuming PEP 558 is eventually accepted, will some day reliably *never* work) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

[Python-ideas] Inline assignments using "given" clauses

2018-05-04 Thread Nick Coghlan
h" for a purpose along these lines, which runs into a different set of problems related to trying to use "with" for two distinct and entirely unrelated purposes). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _

Re: [Python-ideas] A way to subscript a single integer from bytes

2018-05-01 Thread Nick Coghlan
gt;> a = b'hovercraft' > >>> int.from_bytes(a, 'big') > 493182234161465432041076 > It's also worth noting that if there's more than one integer of interest in the string, than using the struct module is often going to be better than using multipl

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Nick Coghlan
On 29 April 2018 at 21:24, Chris Angelico wrote: > On Sun, Apr 29, 2018 at 6:03 PM, Nick Coghlan wrote: > > The challenge with doing this implicitly is that there's no indication > > whatsoever that the two "e"'s are different, especially given the > > l

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Nick Coghlan
wouldn't be possible for code compiled in "single" mode, although working out a suitable relationship between sublocal scoping and the interactive prompt is likely to prove tricky no matter what) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-27 Thread Nick Coghlan
you or someone else has previously run "import package.submodule" (or an equivalent) The current attribute error is cryptic (and not always raised if some other module has already done the import!), so trying the submodule import implicitly would also provide an opportunity to customise

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-27 Thread Nick Coghlan
er(name_of_first_param, __class__)". And even that limited bit of magic has proven quirky enough to be a recurring source of irritation when it comes to interpreter maintenance. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-27 Thread Nick Coghlan
't explicitly import them - you'd only be *required* to explicitly import top level modules, with everything under that being an implementation detail of that top level package) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-26 Thread Nick Coghlan
om pkg import .mod1, .mod2, .mod3 to only bind "pkg" locally, but still make sure "pkg.mod1", "pkg.mod2" and "pkg.mod3" all resolve at import time. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia __

Re: [Python-ideas] Change magic strings to enums

2018-04-26 Thread Nick Coghlan
7;Enum' is not JSON serializable The mixin variants basically say "If you run into code that doesn't natively understand enums, act like an instance of this type". Since most of the standard library has been around for years, and sometimes even decades, we tend to face a

Re: [Python-ideas] Change magic strings to enums

2018-04-24 Thread Nick Coghlan
es, importing "types" and "_collections" accounted for around a 3rd of the time, with the bulk of the execution time being enum's own module level code. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia __

Re: [Python-ideas] Change magic strings to enums

2018-04-24 Thread Nick Coghlan
could potentially be made for converting some of the inspect module state introspection APIs over to StringEnum, so it was easier to iterate over the valid states in a consistent way, but even there I'd need to see a concrete proposal before I made up my mind). Making the case for IntEnum us

Re: [Python-ideas] Change magic strings to enums

2018-04-24 Thread Nick Coghlan
). At a less philosophical level, many of the cases where we use magic strings are in code that has to work even when the import system isn't working yet - that's relatively straightforward to achieve when the code is only relying on strings with particular contents, but *much* harder if t

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Nick Coghlan
"with subexpr as target". So the main concern around "with (name as expr)" is with human readers getting confused, not the compiler, as we can tell the latter to implement whichever semantics we decide we want, while humans are far less tractable :) Cheers, Nick. -- Nick C

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Nick Coghlan
On 16 April 2018 at 03:45, Steve Barnes wrote: > On 15/04/2018 08:12, Nick Coghlan wrote: >> The discoverability of these kinds of techniques could definitely >> stand to be improved, but the benefit of adopting them is that they >> work on all currently supported ver

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-15 Thread Nick Coghlan
s, if you mess it up you can cause significant data loss, and anyone that already knows they need atomic rewrites is likely to be able to come up with their own purpose specific implementation in less time than it would take them to assess the suitability of 3rd party alternatives). Cheers, Ni

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-15 Thread Nick Coghlan
as name": also prevents "modname" getting bound in the current scope the way it normally would * "except exc_filter as exc": binds the caught exception, not the exception filter * "with cm as name": binds the result of

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-15 Thread Nick Coghlan
On 15 April 2018 at 13:54, Chris Angelico wrote: > On Sun, Apr 15, 2018 at 1:08 PM, Nick Coghlan wrote: >> === Target first, 'from' keyword === >> >> while (value from read_next_item()) is not None: # New >> ... >> >> Pros

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-15 Thread Nick Coghlan
On 15 April 2018 at 17:12, Nick Coghlan wrote: > If you want to do this dynamically relative to the current module, > then it's possible to do: > > global __path__ > __path__[:] = (some_directory, some_other_directory) > custom_mod = importlib.import_module(&q

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-15 Thread Nick Coghlan
initely stand to be improved, but the benefit of adopting them is that they work on all currently supported versions of Python (even importlib.import_module exists in Python 2.7 as a convenience wrapper around __import__), rather than needing to wait for new language level syntax for them.

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-14 Thread Nick Coghlan
when combined with other uses of ":" as a syntactic marker (e.g. slices, dict key/value pairs, lambda expressions, type annotations) === Target first, 'from' keyword === while (value from read_next_item()) is not None: # New ... Pros: * avoids the syntactic ambi

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-13 Thread Nick Coghlan
on model, and the import emulation recipe doesn't is intended as a hint :) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-13 Thread Nick Coghlan
unambigous in with statement headers with create_cm() -> cm as enter_result: ... (Pronunciation-wise, if we went with that option, I'd probably pronounce "->" as "as" most of the time, but there are some cases like the "while" exa

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-13 Thread Nick Coghlan
ence table memorized, and there isn't any simple way for my text editor to help me out). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.or

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-12 Thread Nick Coghlan
On 12 April 2018 at 07:28, Chris Angelico wrote: > On Thu, Apr 12, 2018 at 1:22 AM, Nick Coghlan wrote: >>> Frequently Raised Objections >>> >> >> There needs to be a subsection here regarding the need to call `del` >> at class

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-12 Thread Nick Coghlan
op level name binding expressions in with statements: "with (expr as name):" and "with expr as name:" were far too different semantically for the only syntactic difference to be a surrounding set of parentheses. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | B

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Nick Coghlan
s at those scopes. > This could be used to create ugly code! > --- > > So can anything else. This is a tool, and it is up to the programmer to use > it > where it makes sense, and not use it where superior construct

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Nick Coghlan
or an alternate pyc compiler frontend like Hylang could use it to provide relevant references back to the original source code (JavaScript's source maps may provide inspiration on that front). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia

Re: [Python-ideas] Add more information in the header of pyc files

2018-04-11 Thread Nick Coghlan
20 bytes to see the new signature byte (which shouldn't be a problem, given that file defaults to reading up to 1 MiB from files it is trying to identify). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python

Re: [Python-ideas] Start argument for itertools.accumulate() [Was: Proposal: A Reduce-Map Comprehension and a "last" builtin]

2018-04-09 Thread Nick Coghlan
(accumulate(iterable, binop, initial=value)))". Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-04-09 Thread Nick Coghlan
On 9 April 2018 at 01:01, Steven D'Aprano wrote: > On Sun, Apr 08, 2018 at 09:25:33PM +1000, Nick Coghlan wrote: > >> I was writing a new stdlib test case today, and thinking about how I >> might structure it differently in a PEP 572 world, and realised that a >> situ

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-04-08 Thread Nick Coghlan
cwd()), and it occurred to me that a version of PEP 572 that omits the sublocal scoping concept will allow inline naming of parts of data structures as you define them. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Pyth

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-07 Thread Nick Coghlan
irritating, especially when demonstrating behaviour at the interactive prompt. Being able to reliably exhaust an iterator with "last(iterable)" or "itertools.last(iterable)" would be a nice reduction function to offer, in addition to our existing complement of builtin reducers

  1   2   3   4   5   6   7   8   >