[Python-ideas] Re: Should Python enforce Type-checking in the future?

2021-12-09 Thread Caleb Donovick
First off I love types. They, as you point out, are a great tool for finding bugs. However, there are reasons why requiring types would either require the use of meaningless types e.g. marking everything as the Any type or require python to solve the halting problem. Consider the following code e

[Python-ideas] Re: Should Python enforce Type-checking in the future?

2021-12-09 Thread Caleb Donovick
r object). Now if libraries are going to be forced to just throw Any everywhere what's the point? -- Caleb Donovick On Thu, Dec 9, 2021 at 3:58 PM Caleb Donovick wrote: > First off I love types. They, as you point out, are a great tool for > finding bugs. However, there are reasons why

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Caleb Donovick
t the interpreter is not lying to them. I think storing the intermediate results on the stack is vastly preferable to revaluation for this reason. On Mon, Oct 4, 2021 at 3:20 PM Chris Angelico wrote: > On Tue, Oct 5, 2021 at 9:02 AM Caleb Donovick > wrote: > > > > > I w

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Caleb Donovick
> I wonder, could this be simplified a bit, on the assumption that a > well-written assertion shouldn't have a problem with being executed > twice? While I agree as an engineering principle an assert should not have side effects and hence re-evaluation should be fine in most cases, it is not unive

[Python-ideas] Re: String comprehension

2021-05-03 Thread Caleb Donovick
For the record I am definitely a -1 on this. The arguments against are overwhelming and the arguments for are pretty weak. However I felt the need to rebut: > Tests don't really count, so there's a small handful here. Tests 100% count as real use cases. If this is a pattern that would be usef

[Python-ideas] Re: Allow syntax "func(arg=x if condition)"

2021-03-22 Thread Caleb Donovick
Never needed this for lists but definitely had the pain for kwargs. Seems very reasonable for that use case, +0.5. In libraries I control I can make sure to use the same default values for functions and their wrappers. However when wrapping functions I don't control there is not a great way to do

[Python-ideas] Re: shouldn't slices be iterable ?

2021-03-18 Thread Caleb Donovick
Or perhaps more problematic what happens if only stride is specified? On Thu, Mar 18, 2021 at 6:09 PM Chris Angelico wrote: > On Fri, Mar 19, 2021 at 10:46 AM Cameron Simpson wrote: > > > > I know that range(start,end,stride) will produce what I'd want from > > iter(slice(start,end,stride)), bu

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-05 Thread Caleb Donovick
> __all__ = (Class.__name__, func.__name__, ...) > > So I have to put it at the end of the module. I do this because if I > change the class or function name and I forget to change it in > __all__, I get an exception. I certainly will not claim to be the arbitrator of good and bad practices but th

[Python-ideas] Re: Alternate lambda syntax

2021-02-23 Thread Caleb Donovick
I was +0.5 on the arrow syntax for `Callable`. It seemed like a nice short hand but understood the arguments against it in the vain of "There should be one-- and preferably only one --obvious way to do it." But > The latter is the same as the former, just in the AST form. That's what > we ask p

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-07 Thread Caleb Donovick
ith. -- Caleb Donovick On Wed, Oct 7, 2020 at 3:38 PM David Mertz wrote: > On Wed, Oct 7, 2020 at 6:24 PM Caleb Donovick > wrote: > >> Itertools.count was an example (hence the use of "e.g.") of an iterator >> which can be efficiently >> advanced witho

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-07 Thread Caleb Donovick
ator but one might want to sample every N'th header. On Wed, Oct 7, 2020 at 3:06 PM Caleb Donovick wrote: > > For `__advance__` to be an official Python protocol, it would almost > > certainly have to be of use for *general purpose iterators*, not just > > speci

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-07 Thread Caleb Donovick
ions of a stream. The beauty of iterators is you don't need to be concerned with the underlying data structure. Ideally I shouldn't need to write two versions of some parse function one which operates on sequences and one that operates on iterables, just so I can efficiently `advance` the s

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-06 Thread Caleb Donovick
`__advance__` a tree iterator). My ladder two examples demonstrate that this could have utility outside of sequences but for iterators in general. -- Caleb Donovick On Tue, Oct 6, 2020 at 1:13 PM David Mertz wrote: > > On Tue, Oct 6, 2020, 1:21 PM Christopher Barker > >> if you w

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-16 Thread Caleb Donovick
*unconcerned (sorry for the spam) On Sun, Aug 16, 2020 at 3:57 PM Caleb Donovick wrote: > > Fine, so the use case you claimed was fiction. If you had just said > "DSL" instead of "anonymous protocols and dataclasses" you would have > gotten straight to the poin

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-16 Thread Caleb Donovick
rote: > On Sat, Aug 15, 2020 at 7:14 PM Caleb Donovick > wrote: > >> > To me, the main weakness here is that you couldn't move forward with >> this unless you also got the various static type checkers on board. But I >> don't think those care much about t

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-15 Thread Caleb Donovick
thing special about the square brackets other than notation but having a visual distinction of type creation and instantiation is useful. On Sat, Aug 15, 2020 at 3:44 PM David Mertz wrote: > On Sat, Aug 15, 2020 at 4:38 PM Caleb Donovick > wrote: > >> > Why would it requir

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-15 Thread Caleb Donovick
on the list so we won't mention that :) On Sat, Aug 15, 2020 at 4:05 PM Guido van Rossum wrote: > On Fri, Aug 14, 2020 at 4:38 PM Caleb Donovick > wrote: > >> My own personal use for this would be for generating anonymous protocols >> and dataclasses: >> >>

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-15 Thread Caleb Donovick
vid Mertz wrote: > > On Fri, Aug 14, 2020, 7:53 PM Caleb Donovick > wrote: > >> > I don't see what that can possible get you that `Struct(x=int, y=str)` >> doesn't. >> >> Using `Struct(x=int, y=str)` requires a metaclass, where `Struct[x=int

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-15 Thread Caleb Donovick
s one for building the protocol and one for building the dataclass but thats because of stupid engineering requirements). On Fri, Aug 14, 2020 at 11:14 PM Steven D'Aprano wrote: > On Fri, Aug 14, 2020 at 04:07:33PM -0700, Caleb Donovick wrote: > > My own personal use for this w

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Caleb Donovick
> I don't see what that can possible get you that `Struct(x=int, y=str)` doesn't. Using `Struct(x=int, y=str)` requires a metaclass, where `Struct[x=int, y=str]` does not. On Fri, Aug 14, 2020 at 4:45 PM David Mertz wrote: > On Fri, Aug 14, 2020, 7:39 PM Caleb Donovick >

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Caleb Donovick
My own personal use for this would be for generating anonymous protocols and dataclasses: class T(Protocol): x: int y: str # with some abuse of notation obviously these would generate unique typesassert T == Struct[x=int, y=str] # similarly @dataclassclass S: x: int y: str assert S =

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-15 Thread Caleb Donovick
I have wanted this and suggested it before for use with typing. Defining protocols is obnoxiously verbose for "struct" like data and keyword arguments to subscript could help alleviate that. I often want to write type hint like this: ``` def foo(x: Protocol[id=int, name=str]): bar(x)

[Python-ideas] Re: url imports

2020-06-10 Thread Caleb Donovick
> i.e. instead of > `pip install package` > and > `import package` > and > `pip freeze > requirements.txt` > for every import, I am unclear on what you mean by "for every import". I have never once done this and I maintain half a dozen packages. Do people really not know what the requirements of

[Python-ideas] Re: Optional keyword arguments

2020-05-18 Thread Caleb Donovick
Certainly the way default arguments work with mutable types is not the most intuitive and I think your complaint has some merit. However how would you define the following to work: def foo(): cons = [set(), [], (),] funs = [] for ds in cons: def g(arg:=ds): return

[Python-ideas] Re: PEP 618: Add Optional Length-Checking To zip

2020-05-01 Thread Caleb Donovick
> but the main > benefit is, again, being able to get the iterated values which were > silently swallowed by zip when the iteration stopped. I don't think the call back idea is terrible, however, it doesn't really seem to have a usecase that isn't covered by zip_longest with a sentinel. Now as d

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-24 Thread Caleb Donovick
g variant maps is trivial: def map_strict(f, *iters): return starmap(f, zip_strict(iters)) - Caleb Donovick On Fri, Apr 24, 2020 at 10:57 AM Serhiy Storchaka wrote: > 24.04.20 07:58, Andrew Barnert via Python-ideas пише: > > And not only that, the PEP for this first step has to make

[Python-ideas] Re: Proposed class for collections: dynamicdict

2020-04-16 Thread Caleb Donovick
new thread for my idea. Caleb On Wed, Apr 15, 2020 at 6:35 PM Steven D'Aprano wrote: > On Mon, Apr 13, 2020 at 06:43:53PM -0700, Caleb Donovick wrote: > > > > Why can’t you just subclass dict and override that? > > > > Because TypeError: multiple bases have ins

[Python-ideas] Re: Proposed class for collections: dynamicdict

2020-04-15 Thread Caleb Donovick
rnert via Python-ideas < > python-ideas@python.org> wrote: > >> On Apr 13, 2020, at 18:44, Caleb Donovick >> wrote: >> >>  >> I have built this data structure countless times. So I am in favor. >> >> >> Maybe you can give a concrete e

[Python-ideas] Re: Proposed class for collections: dynamicdict

2020-04-13 Thread Caleb Donovick
lso give MissingMapping its own metaclass # and do the modification of __getitem__ there. def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) cls.__getitem__ = usemissing(cls.__getitem__) @abstractmethod def __missing__(self, key): pass ``` Caleb Donovick On Fri

[Python-ideas] Re: Live variable analysis -> earlier release?

2020-04-08 Thread Caleb Donovick
This would almost certainly break my code. As a DSL developer I do a lot of (exec | eval | introspection | ... ) shenanigans, that would make doing liveness analysis undecidable. On Wed, Apr 8, 2020 at 10:51 AM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Apr 8, 2020,

[Python-ideas] Re: Incremental step on road to improving situation around iterable strings

2020-02-25 Thread Caleb Donovick
> > Is there a reason mypy could not assume that all AtomicStr methods that > return strings actually return an AtomicStr, without impacting runtime > behavior...? Maybe it's not possible and I'm just not familiar enough with > the behavior of the type checkers. > I don't know but I could say that

[Python-ideas] Re: Incremental step on road to improving situation around iterable strings

2020-02-24 Thread Caleb Donovick
So I do not have extensive experience with mypy but I don't see how it would help. The entire issue that is that `str` is an instance of `Iterable[str]` so how is mypy going to catch my error of passing a single string instead of an iterable of strings to a function? However the ability to distin

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-08 Thread Caleb Donovick
allowed in a subscript. Edit my original grammar change proposal to: ``` subscriptlist: ... | kwargsubscript (',' kwargsubscript )* [','] kwargsubscript: NAME '=' subscript ``` Now slices are allowed in keyword arguments. -- Caleb Donovick On Tue, Oct 8, 2019 at 1:09 P

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> It captures a tiny fraction of Pandas style filtering while complicating the syntax of Python Sure maybe I we can't represent all filters super concisely but at least inequalities, or any filter on single axis, would not be hard. E.g. db[x=LT(1)] == db[db.x < 1] Granted I don’t really see a w

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> But what if you wanted to take both positional AND keyword? I was suggesting that that wouldn't be allowed. So subscript either has a single argument, a tuple of arguments, or a dictionary of arguments. Allowing both has some advantages but is less cleanly integratible. -- Caleb Dono

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
oing to get weird. However, I'd rather not have all the special casing that comes with keyword arguments. On Mon, Oct 7, 2019 at 7:57 PM Andrew Barnert wrote: > On Oct 7, 2019, at 14:56, Caleb Donovick wrote: > > > > > I think it might be better if it actually passed them

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
member any serious criticism of this idea. It’s just that the >> authors of that proposal lost interest and it did not receive further >> progress. And in this regard, over time, it was abandoned. >> >> with kind regards, >> -gdg >> >> пт, 4 окт. 2019 г. в 2

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
t 7, 2019 at 5:56 PM Caleb Donovick wrote: > > I think it might be better if it actually passed them as keyword > arguments. > > If only keyword arguments are passed what happens to the positional > index? Is it the empty tuple? > > Currently subscript with no index (`d

[Python-ideas] Allow kwargs in __{get|set|del|}item__

2019-10-04 Thread Caleb Donovick
I don't really know anything about parsers but I think the grammar could be extended without issue with the following rule: ``` subscriptlist: ... | kwargsubscript (',' kwargsubscript )* [','] kwargsubscript: NAME '=' test ``` if `NAME '=' test` woul

[Python-ideas] Re: Extend ast with types for * instead of using raw lists

2019-08-16 Thread Caleb Donovick
> > Maybe moving to another lib like parso actually helps your real problem > more... > > > On 15 Aug 2019, at 22:02, Caleb Donovick > wrote: > > > > When walking an ast it impossible to know the type of an empty list > without writing down some giant lookup from nod

[Python-ideas] Re: Extend ast with types for * instead of using raw lists

2019-08-16 Thread Caleb Donovick
ict between AST and list. Caleb Donovick On Fri, Aug 16, 2019 at 5:54 AM Ivan Levkivskyi wrote: > On one hand I can see how this may cause little inconvenience, but on > other hand this would be a breaking change, so I don't think it is > realistic. > Also I think this is oft

[Python-ideas] Extend ast with types for * instead of using raw lists

2019-08-15 Thread Caleb Donovick
on stuff like `if isinstance(node.field, list)` e.g. the implementation of generic_visit. Caleb Donovick ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman

[Python-ideas] venv.EnvBuilder environmental variable hooks

2019-06-18 Thread Caleb Donovick
/venv/scripts/common/activate#L16 Full activate / deactivate hooks could be achieved by setting __VENV_*_EXTRAS__ to be arbitrary shell commands. Caleb Donovick ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: Operator as first class citizens -- like in scala -- or yet another new operator?

2019-06-18 Thread Caleb Donovick
scussion beyond assign in place to be a write operator we can add to the list ``` coroutine.send(args) process.communicate(args) file.write(arg) ``` Caleb Donovick On Tue, Jun 18, 2019 at 3:43 PM nate lust wrote: > I have been following this discussion for a long time, and coincidentally > I

[Python-ideas] Re: Operator as first class citizens -- like in scala -- or yet another new operator?

2019-06-17 Thread Caleb Donovick
ge the semantic of =. What Yanghao and I are asking for is an in-place update/assign operator which isn't burdened with numeric meaning. Caleb Donovick On Thu, Jun 13, 2019 at 1:42 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Caleb Donovick writes: > >

[Python-ideas] Re: Operator as first class citizens -- like in scala -- or yet another new operator?

2019-06-12 Thread Caleb Donovick
Barry the reason I use python and don't parse syntax directly as I want to have python as meta programming environment for my DSLs. I can mostly work within the python syntax (with some pretty heavy metaclasses) I rarely have to touch the AST. Their only two places where I ever have to touch the

[Python-ideas] Re: Assign-in-place operator

2019-06-11 Thread Caleb Donovick
The problem as I see it with slice assignment is that if we want to operator to mean type defined assignment not necessary in place assignment. It creates confusion for types which have __setitem__. Caleb Donovick On Thu, Jun 6, 2019 at 4:59 PM Greg Ewing wrote: > Stephen J. Turnbull wr

[Python-ideas] Re: Operator as first class citizens -- like in scala -- or yet another new operator?

2019-06-10 Thread Caleb Donovick
# raises TypeError 'a' is not a int S = ''' def foo(): # type of foo inferred x = int x = 'a' foo() ''' exec(S, TypeCheckDict(), TypeCheckDict()) # doesn't raise an error as a normal dict is used in foo ``` Caleb Donovick On Th