[issue43817] Add typing.get_annotations()

2021-04-16 Thread Guido van Rossum


Guido van Rossum  added the comment:

Putting it in inspect makes sense then.

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-16 Thread Larry Hastings


Larry Hastings  added the comment:

Assuming this function is added for Python 3.10, I propose that uses of 
typing.get_type_hints() in the standard library that aren't specifically 
dealing with type hints should change to calling this function instead.  I 
currently know of two sites:

   * inspect.signature()
   * functools.singledispatch()

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-16 Thread Guido van Rossum


Guido van Rossum  added the comment:

Also, for crosslinking, see issue43463.

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-16 Thread Larry Hastings


Larry Hastings  added the comment:

> Should this feature implemented in typing module? How about inspect module?

That's a reasonable idea.

Part of the reasoning behind putting it in the typing module was to share its 
implementation with typing.get_type_hints().  However, I was reading the source 
to typing.get_type_hints() yesterday, and its implementation is completely 
based on the assumption that the annotations are type hints.  It might be 
possible to rework its implementation to isolate these assumptions, but the 
remaining shared code would be probably less than fifty lines.  So the code 
reuse isn't a big deal.

If the two functions don't share an implementation, you're right, the inspect 
module is probably a better place for this new function.


> Additionally, how about adding `get_annotation_str()`, which returns str 
> always? Some use cases (e.g. `help(f)`) need just string. I want to skip 
> eval() in it.

I don't know if I'd want to add a third function.  Perhaps a parameter to 
get_annotation?  eval_str=True?

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-16 Thread Inada Naoki


Inada Naoki  added the comment:

Should this feature implemented in typing module? How about inspect module?

Additionally, how about adding `get_annotation_str()`, which returns str always?
Some use cases (e.g. `help(f)`) need just string. I want to skip eval() in it.

--
nosy: +methane

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-16 Thread Barry A. Warsaw


Change by Barry A. Warsaw :


--
nosy: +barry

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-13 Thread Ken Jin


Change by Ken Jin :


--
nosy: +kj

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Jelle Zijlstra


Change by Jelle Zijlstra :


--
nosy: +Jelle Zijlstra

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Larry Hastings


Larry Hastings  added the comment:

> I'd say just submit the PR. Shouldn't be problematic.

Okey-doke, I can do it.  Though I have plenty to do at the moment, though, so 
it wouldn't be this week.

Is there anybody who would *enjoy* taking this on, who we could farm it out to? 
 If not, that's no problem, I should be able to get it done before 3.10b1.


> (Have you decided what to do if the eval() fails?)

My experience is that typing.get_type_hints() doesn't catch exceptions, e.g. 
NameError.  I assumed that typing.get_annotations() should behave the same way.

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Guido van Rossum


Guido van Rossum  added the comment:

I'd say just submit the PR. Shouldn't be problematic. (Have you decided
what to do if the eval() fails?)

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Larry Hastings


Larry Hastings  added the comment:

To be honest, I'm not 100% sure.  But I observe that typing.get_type_hints() is 
about fifty lines of code, and very few of them are the opinionated lines I 
want to avoid.

Some things typing.get_type_hints() seems to do for you:
* Work around the "classes inherit annotations" design bug.
* Unwrap wrapped functions.
* "Return empty annotations for something that _could_ have them."

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Guido van Rossum


Guido van Rossum  added the comment:

It's fair that get_type_hints() does too much. But what does your proposed 
function do besides this?

{k: eval(v) for k, b in x.__annotations__.items()}

?

--

___
Python tracker 

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



[issue43817] Add typing.get_annotations()

2021-04-12 Thread Larry Hastings


Larry Hastings  added the comment:

(realized mid-issue-creation that it should have a different name)

--
title: Add typing.eval_annotations() -> Add typing.get_annotations()

___
Python tracker 

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