Skip to content

Add common issue docs for PEP585 syntax update #14246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LefterisJP
Copy link
Contributor

As discussed with @AlexWaygood in #14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP584 syntax

@AlexWaygood AlexWaygood self-requested a review December 4, 2022 13:10
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! I've left a few suggestions below.

Main points:

  • It's PEP 585, not PEP 584 :)
  • Stick to <=80 characters per line where possible.
  • type is a builtin name, but it's not a keyword
  • Use Sphinx roles to add links where appropriate

@LefterisJP LefterisJP force-pushed the docs_for_pep584_syntax_upgrade branch from 9bf1d9a to b595128 Compare December 4, 2022 15:38
@LefterisJP
Copy link
Contributor Author

Thanks! I've left a few suggestions below.

Main points:

  • It's PEP 585, not PEP 584 :)
  • Stick to <=80 characters per line where possible.
  • type is a builtin name, but it's not a keyword
  • Use Sphinx roles to add links where appropriate

Thanks I addressed all your points. Didn't know of the sphinx roles and links. The off by one error is funny 🤣

I left you two extra questions

@AlexWaygood
Copy link
Member

The off by one error is funny 🤣

You need to update the title of the PR as well ;)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! A few more points:

@LefterisJP LefterisJP changed the title Add common issue docs for PEP584 syntax upgrade Add common issue docs for PEP585 syntax update Dec 4, 2022
@LefterisJP LefterisJP force-pushed the docs_for_pep584_syntax_upgrade branch from b595128 to a9e081d Compare December 4, 2022 16:35
@LefterisJP
Copy link
Contributor Author

You need to update the title of the PR as well ;)

Done!

Thanks! A few more points:

Addressed them and pushed.

One question from my side. Here I asked you if you know the sphinx link to type for the docs. Any idea? This does not seem to render properly. But I see the same problem in other places in the docs as per my comment.

@AlexWaygood
Copy link
Member

AlexWaygood commented Dec 4, 2022

One question from my side. Here I asked you if you know the sphinx link to type for the docs. Any idea? This does not seem to render properly. But I see the same problem in other places in the docs as per my comment.

Hmm, maybe try

:py:class:`type`

@LefterisJP LefterisJP force-pushed the docs_for_pep584_syntax_upgrade branch from a9e081d to 792fb72 Compare December 4, 2022 16:58
@LefterisJP
Copy link
Contributor Author

LefterisJP commented Dec 4, 2022

One question from my side. Here I asked you if you know the sphinx link to type for the docs. Any idea? This does not seem to render properly. But I see the same problem in other places in the docs as per my comment.

Hmm, maybe try

:py:class:`type`

Yeah! That seems to work! Generates a proper link to: https://docs.python.org/3/library/functions.html#type

I pushed it to the PR.

Follow up question then. There is one more place in the docs where this needs fixing. Should I do it in this PR and a separate commit? A different PR? I am not sure what workflow you guys prefer.

@AlexWaygood
Copy link
Member

Follow up question then. There is one more place in the docs where this needs fixing. Should I do it in this PR and a separate commit? A different PR? I am not sure what workflow you guys prefer.

That would be a very welcome fix, but definitely best to do it as a separate PR, since it's a different issue to the thing being tackled here :)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Looks great now! Just two minor points:

As discussed with @AlexWaygood in
python#14245 (comment)
adding a common issue entry for the problem of hitting overshadowing a
built-in keyword when upgrading to PEP585 syntax
@LefterisJP LefterisJP force-pushed the docs_for_pep584_syntax_upgrade branch from 792fb72 to 281d279 Compare December 4, 2022 17:15
@LefterisJP
Copy link
Contributor Author

Looks great now! Just two minor points:

Addressed both. And also opened that follow-up PR.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM!

@JelleZijlstra
Copy link
Member

It's a bit weird to frame this around PEP 585, when PEP 585 doesn't really do anything special here: you can run into the exact same problem with types like int and str that have always been usable as annotations. Indeed there is already a section in "Common issues" about this: https://mypy.readthedocs.io/en/stable/common_issues.html#dealing-with-conflicting-names. So if anything, we should enhance that section.

I would also recommend removing the recommendation to use typing.Type. One of the effects of PEP 585 is that things like "type" and "list" are no longer special in the sense that they have a separate typing alter ego. That's good for learning because users no longer have to remember which names are special like that. So we shouldn't point users to typing.Type; people working in a post-PEP 585 world shouldn't need to know it even exists.

@LefterisJP
Copy link
Contributor Author

It's a bit weird to frame this around PEP 585, when PEP 585 doesn't really do anything special here: you can run into the exact same problem with types like int and str that have always been usable as annotations. Indeed there is already a section in "Common issues" about this: https://mypy.readthedocs.io/en/stable/common_issues.html#dealing-with-conflicting-names. So if anything, we should enhance that section.

I would also recommend removing the recommendation to use typing.Type. One of the effects of PEP 585 is that things like "type" and "list" are no longer special in the sense that they have a separate typing alter ego. That's good for learning because users no longer have to remember which names are special like that. So we shouldn't point users to typing.Type; people working in a post-PEP 585 world shouldn't need to know it even exists.

Thank you for the review @JelleZijlstra @AlexWaygood. So how would you like me to proceed with the PR to get it merged? Add the section as is under the section you recommended removing:

  1. references to PEP584?
  2. The recommendation to use typing.Type ?

@JelleZijlstra
Copy link
Member

Yes, I'd recommend adding a shortened text under the existing section. It's probably helpful to use type as the main example since that's in my experience the most common name for which this problem comes up.

@JelleZijlstra JelleZijlstra removed their request for review December 20, 2022 21:54
hauntsaninja pushed a commit that referenced this pull request Dec 20, 2022
Switch :py:func:type to py:class:type in type_narrowing.rst. The former does not render properly in the docs

This is a tiny follow up from
#14246 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants