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

2021-12-13 Thread Brendan Barnwell
On 2021-12-13 17:07, Steven D'Aprano wrote: >As an aside, seeing what the docs say about Annotated makes me think >that "Annotated" is a very bad name for this thing. It confuses the >idea of a type annotation (i.e., attached to a variable) with this >type-incorporating-a-label, where neithe

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

2021-12-13 Thread Paul Bryan
If we proceed with using `Annotated`, I suggest it be the last string in the metadata. Using your example: spam: Annotated[ int, Positive, GreaterThan[1], "Doc string goes here..." Union[Odd|Literal[2]], Prime, Wibble, Wobble, ] = 2 In other words, strings would be reserved to spe

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

2021-12-13 Thread Steven D'Aprano
On Sun, Dec 12, 2021 at 07:43:16PM -0800, Brendan Barnwell wrote: > The question is what does this annotate: > > Annotated[int, "some text here"] Nothing. There's no annotation there. That's an expression which returns a type alias. It is just an object. You can print it, put it in a lis

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

2021-12-13 Thread Steven D'Aprano
Thinking more about my example here: On Tue, Dec 14, 2021 at 01:50:45AM +1100, Steven D'Aprano wrote: > class MyClass: > """Blah blah blah. > > Variable annotations of the form Annotated[T, 'string', *args] > always interpret the string in the second position as a >

[Python-ideas] Re: Python standard library TOML module

2021-12-13 Thread Neil Girdhar
FYI: The flake8 project refuses to add toml configuration file support in part because there is no standard library toml module: https://github.com/PyCQA/flake8/issues/234#issuecomment-812800722 The thread was eventually locked by the project owner, and a project sprang up to try to address the

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

2021-12-13 Thread Jon Kiparsky
I've been holding off commenting on this because frankly y'all talk a hell of a lot and I'm still about five days back trying to keep up with all the back-and-forth. So probably some of this repeats something that's been said and I apologize for that, but I did want to put my two cents' worth in.

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

2021-12-13 Thread Christopher Barker
On Mon, Dec 13, 2021 at 6:54 AM Steven D'Aprano wrote: > > Okay, I'm sorry, I understand the statement to be referring to people > who had no intention of using type-hints. For those people, > no_type_hints is the right solution. But for those who want type hints > as well as docstrings, it is no

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

2021-12-13 Thread Christopher Barker
On Mon, Dec 13, 2021 at 7:14 AM Simão Afonso < simao.afo...@powertools-tech.com> wrote: > What about having a docstring but no typing information? In this case > that's impossible, no? spam: Annotated[Any, 'Yummy meat-like product'] or spam: Annotated[None, 'Yummy meat-like product'] -CHB ___

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

2021-12-13 Thread Stephen J. Turnbull
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 create a way for it to work. > > By default, for arbitrary classes, no, it *shouldn't* wor

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

2021-12-13 Thread Simão Afonso
On 2021-12-14 01:50:45, Steven D'Aprano wrote: > On Sun, Dec 12, 2021 at 12:23:54PM -0800, Christopher Barker wrote: > > And I note that Annotated flattens nested Annotated types, so having both a > > docstring and other use of Annotated could be a bit tricky. > > class MyClass: > """B

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

2021-12-13 Thread Steven D'Aprano
On Sun, Dec 12, 2021 at 12:23:54PM -0800, Christopher Barker wrote: > > the tools will follow. Runtime tools will > > look at the dunder, static tools will look at the annotation directly. > > > > I hope not. *maybe* inspect.get_annotations() though. Sorry, I don't understand your position here.

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

2021-12-13 Thread Steven D'Aprano
On Sun, Dec 12, 2021 at 05:34:33PM -0800, Paul Bryan wrote: > 1. While I agree that assigning the `Annotated` value to `SomeType` > makes `SomeType` a type alias, what do you call the specific instance > of `Annotated[...]` itself? Its a type. The specific type is a private implementation detail: