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
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
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
> 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
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
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
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
> __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
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
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
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
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
`__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
*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
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
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
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:
>>
>>
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
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
> 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
>
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 =
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)
> 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
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
> 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
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
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
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
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
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,
>
> 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
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
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
> 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
> 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
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
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
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
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
>
> 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
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
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
/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
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
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:
>
>
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
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
# 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
48 matches
Mail list logo