[issue45380] help() appears confused about the module of typing.Annotated

2022-02-03 Thread Guido van Rossum


Guido van Rossum  added the comment:

It looks like __metadata__ was *meant* to be a public attribute, but somehow 
overseen when the PEP and docs were written. :-(

I don't know anything about this class, really.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45380] help() appears confused about the module of typing.Annotated

2022-02-03 Thread jack1142


Change by jack1142 :


--
nosy: +jack1142

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45380] help() appears confused about the module of typing.Annotated

2021-10-10 Thread Alex Waygood


Change by Alex Waygood :


--
nosy: +gvanrossum, kj

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45380] help() appears confused about the module of typing.Annotated

2021-10-10 Thread Alex Waygood


Alex Waygood  added the comment:

It actually appears as though there is no documented way to retrieve the 
metadata from an annotated alias. Is this intentional?

The metadata is stored in a `__metadata__` attribute of a 
`typing._AnnotatedAlias` instance. But the `__metadata__` attribute is 
undocumented -- there is no mention of it in the docstring for 
`_AnnotatedAlias`, in the documentation for `typing.Annotated` 
(https://docs.python.org/3.11/library/typing.html#typing.Annotated), or PEP 
593, which introduced `typing.Annotated` 
(https://www.python.org/dev/peps/pep-0593/).

The documentation says: "Passing include_extras=True to get_type_hints() lets 
one access the extra annotations at runtime." However, this is misleading. 
Calling `get_type_hints` on a function/class where an argument/attribute is 
annotated with an `_AnnotatedAlias` instance is a way of retrieving the type 
hints for the function/class with the `_AnnotatedAlias` instance unresolved. 
However, if you call `get_type_hints` on the `_AnnotatedAlias` instance 
directly, this fails.

--
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45380] help() appears confused about the module of typing.Annotated

2021-10-05 Thread Alex Waygood


New submission from Alex Waygood :

`help()` appears confused about the module of `typing.Annotated`. If you call 
`help()` on a parameterised "instance" of `typing.Annotated`, it will claim 
that `Annotated` belongs to whatever module the annotated type is from. 
Additionally, `help()` appears not to know about the `__metadata__` attribute 
of `typing.Annotated`.

```
>>> from typing import Annotated, Callable
>>> t = Annotated[int | str, "Some metadata"]
>>> help(t)
Help on _AnnotatedAlias in module types:

Annotated = int | str
>>> u = Annotated[Callable[[int], str], "Some metadata"]
>>> help(u)
Help on _AnnotatedAlias in module typing:

Annotated = typing.Callable[[int], str]
>>> s = Annotated[int, "Some metadata"]
Help on _AnnotatedAlias in module builtins:

Annotated = class int(object)
 |  int([x]) -> integer
 |  int(x, base=10) -> integer

# (etc., giving the entire output of help() for `int`)
```

--
assignee: docs@python
components: Documentation, Library (Lib)
messages: 403258
nosy: AlexWaygood, docs@python
priority: normal
severity: normal
status: open
title: help() appears confused about the module of typing.Annotated
type: behavior
versions: Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com