Skip to content

Conversation

@larryhastings
Copy link
Contributor

No description provided.

@larryhastings
Copy link
Contributor Author

Pablo: I tagged you because I made two edits not in my section. ISTM the document was using "annotations" where it meant "type hints" in a couple places. Do you agree, or should I back out of those changes?

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Larry, thanks for the patch. When I wrote the sections on type hints, I was using type annotations and hints interchangeably. I forgot that there are subtle differences between the two. Most of the changes LGTM. Thanks for making them!

stringized annotations. :func:`inspect.get_annotations` is now considered
best practice for accessing the annotations dict defined on any Python object.
Relatedly, :func:`inspect.signature`,
:func:`inspect.from_callable`, and `inspect.from_function` now call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing due to this line:

Suggested change
:func:`inspect.from_callable`, and `inspect.from_function` now call
:func:`inspect.from_callable`, and :func:`inspect.from_function` now call

alternatively you can just use double backticks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of :func: these days, definitely going that way with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, maybe I've been thinking about this topic way too long, but I don't think the difference is subtle ;-)

Think of it this way: an annotation is defined by a syntactic context, a type hint is defined as something inheriting from TypeVar (or its stringized equivalent, etc etc). It's true that lots of people only ever use type hints as annotations, and only ever annotate with type hints. But they're still very different concepts--confusing the two is like confusing a function argument and an int.

Copy link
Member

@Fidget-Spinner Fidget-Spinner May 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree with what you said - type hints need not be annotations, it just needs to bear some meaning to the type checker (eg. type comments). Whilst annotations is a purely syntactical construct (well bar some exceptions like in dataclasses and runtime checking)

I only noticed the major difference while I was writing another comment and reflecting for the 10 seconds after posting 😉 . Hence why I promptly deleted that comment after feeling pretty dumb hehe.

PS. regarding `

a type hint is defined as something inheriting from TypeVar

Where can I read more about this? I didn't know and I can't find much info about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I misspoke. There are a couple other things that can be type hints. Types, for example :D

I'm not an expert on typing or type hints. All I can really tell you is that typing._type_check() appears to be as canonical a source as one is likely to find. It smiles upon instances of type, Any, NoReturn, TypeVar, ForwardRef, Union, ParamSpec, and some instances of _GenericAlias. It complains about instances of _SpecialForm, the objects Generic and Protocol, or any callable not previously explicitly permitted. And anything I didn't mention above seems to get a pass, too.

@larryhastings
Copy link
Contributor Author

I fixed the bugs Fidget-Spinner pointed out (I think?), and made a couple more clarifications / edits to What's New In Python 3.10.

I wonder why I don't see the test failures on my machine--make html and make suspicious both run fine, without errors. Is there another command I should be running to reproduce these errors? Is my doc build environment possibly out of date?

@Fidget-Spinner
Copy link
Member

Is there another command I should be running to reproduce these errors?

The checks also run python3 tools/rstlint.py -i tools -i ./venv -i README.rstwhich is located at Doc/tools/rstlint.py. Any warning it emits will cause the bots to error.

Here's a copy of the command the bot runs:
make check html suspicious SPHINXOPTS="-q -W -j4"

So I think if you run make check suspicious , you should get the same result.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@larryhastings larryhastings merged commit 99f71ae into python:master May 1, 2021
@bedevere-bot
Copy link

@larryhastings: Please replace # with GH- in the commit message next time. Thanks!

@larryhastings
Copy link
Contributor Author

Thanks for the review and the feedback!

@larryhastings larryhastings deleted the whats_new_annotations_and_type_hints branch May 1, 2021 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants