[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Steven D'Aprano
On Tue, Dec 14, 2021 at 06:48:57PM -0800, Paul Bryan wrote: > Interesting. Some apparent downsides: > > - doesn't apply to class attributes There is that. > - objects with `__slots__` can't dynamically add attributes  Just give it a `__dict__` slot: __slots__ = {'__dict__': None} and now

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Ricky Teachey
On Tue, Dec 14, 2021, 9:49 PM Paul Bryan wrote: > Interesting. Some apparent downsides: > > - doesn't apply to class attributes > - objects with `__slots__` can't dynamically add attributes > Also doesn't apply to module level members. To my mind these are significant downsides. And it also

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Paul Bryan
Interesting. Some apparent downsides: - doesn't apply to class attributes - objects with `__slots__` can't dynamically add attributes  On Wed, 2021-12-15 at 11:13 +1100, Steven D'Aprano wrote: > Hmmm, well it seems that we already have support for class attribute > docstrings, since Python 3.8.

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Steven D'Aprano
Hmmm, well it seems that we already have support for class attribute docstrings, since Python 3.8. It's not documented, but soon will be. https://bugs.python.org/issue46076 class Card: """A card from a standard French deck""" __slots__ = { 'suit': 'Either "Spades",

[Python-ideas] Re: List comprehension operators

2021-12-14 Thread Steven D'Aprano
On Tue, Dec 14, 2021 at 03:46:06PM -, a.kolpakov2010--- via Python-ideas wrote: > It would be awesome to be able to create a list with just: > > li = [1—100] [1-100] already has a meaning in Python: it computes 1-100 = -99 and puts it in a list. > or > > li = [1 .. 100] Is that an

[Python-ideas] Re: List comprehension operators

2021-12-14 Thread Simão Afonso
On 2021-12-14 15:46:06, a.kolpakov2010--- via Python-ideas wrote: > It would be awesome to be able to create a list with just: > > li = [1—100] > > or > > li = [1 .. 100] What's wrong with > range(1, 100) Do you really want a list only to use in a for loop? What's wrong with the iterator?

[Python-ideas] Re: List comprehension operators

2021-12-14 Thread Finn Mason
list(range(1, 101)) I think we don't need a whole new syntax for something that's already an easy one-liner. -- Finn (Mobile) On Tue, Dec 14, 2021, 8:52 AM a.kolpakov2010--- via Python-ideas < python-ideas@python.org> wrote: > It would be awesome to be able to create a list with just: > > li

[Python-ideas] Re: List comprehension operators

2021-12-14 Thread Matt D
Seems like a lot of work to just make list(range(1,100)) Insignificantly easier to write ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Christopher Barker
Hey all: There is discussion RIGHT NOW in the SC, and on python-dev about future "policy" around annotations, in response to the PEP 563 and 649 -- not clear where it's going to end up, but it is clear that the whole "are annotations only for typing" question will be made more clear. Anyway, I

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Ricky Teachey
On Tue, Dec 14, 2021 at 10:23 AM Joao S. O. Bueno wrote: > Just a short one, for everyone agreeing type.Annotated does the job, > but thinks we need new syntax, because it is verbose: > > You can already do: > > from typing import Annotated as A > > And: > > attr: A[type, "docstring goes

[Python-ideas] List comprehension operators

2021-12-14 Thread a.kolpakov2010--- via Python-ideas
It would be awesome to be able to create a list with just: li = [1—100] or li = [1 .. 100] ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Joao S. O. Bueno
Just a short one, for everyone agreeing type.Annotated does the job, but thinks we need new syntax, because it is verbose: You can already do: from typing import Annotated as A And: attr: A[type, "docstring goes here"] I see no need for any new syntax. (and maybe adding typing.Docstring

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Steven D'Aprano
On Tue, Dec 14, 2021 at 12:38:55AM +0900, Stephen J. Turnbull wrote: > Steven D'Aprano writes: > > On Sun, Dec 12, 2021 at 08:44:25PM -0500, Ricky Teachey wrote: > > > > class C: > > > x: Annotated [Any, "spam"] > > > > > > help(C.x) > > > > > And it seems reasonable to try and

[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-14 Thread Steven D'Aprano
On Mon, Dec 13, 2021 at 05:10:52PM -0800, Paul Bryan wrote: > In other words, strings would be reserved to specify documentation. We can't reserve strings to specify documentation. (1) Strings can be used for forward references. class Node: payload: Any # Arbitrary data.