Skip to content
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

Update docs about variables and aliases #8200

Merged
merged 6 commits into from
Jan 30, 2020
Merged

Update docs about variables and aliases #8200

merged 6 commits into from
Jan 30, 2020

Conversation

TH3CHARLie
Copy link
Collaborator

resolves #3494(Since module types are tracked in #3500)

Following #8187 (comment) and #3494, if I understand correctly and the semantics in #3494's example code has been fixed(report error on re-assign Alias = B, the remaining work of #3494 is to update the docs, which is the main focus of this PR.

Newly added docs are in common issues and solutions section, with the content mostly adapted from Ivan's example in #3494. And a note point to the docs is also added.

When reviewing the PR, I think there are two things to tweak:

  • The section of the docs: common issues or alias type ?
  • The wording: is current example and explantion enough for users to understand the difference

@TH3CHARLie
Copy link
Collaborator Author

Many tests are broken due to the newly added note, I'd like to first confirm the wording and availability of this PR before pervasively modifying the tests

@TH3CHARLie
Copy link
Collaborator Author

I almost forget about this PR.....Now I modify the test suite to apply the new change and pass the tests. But I am worried about that this PR may be too pervasive

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good, I just have an idea about the section title.

docs/source/common_issues.rst Outdated Show resolved Hide resolved
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks!

@JukkaL JukkaL merged commit ea3c65c into python:master Jan 30, 2020
@TH3CHARLie TH3CHARLie deleted the fix-3494 branch February 8, 2020 17:11
@gvanrossum
Copy link
Member

I was just pointed to the docs introduced by this PR (Variables vs type aliases) and for a few moments I was very confused.

Perhaps this was because I was trying to create a type alias for Annotated, which apparently doesn't work (though I think it ought to).

But the docs (copied verbatim from Ivan's text in #3494) did not help. I think what the docs are trying to point out is that both a variable with type Type[A] and an unannotated "variable" initialized with A hold the class object A at runtime, but the type checker sees them differently: the variable tp is a variable holding a class object (that must subclass the given class), and (being a variable) cannot be used in annotations; while the alias is a type definition to the type checker, usable in annotations, and (like other type definitions) is not allowed to be changed.

I'm still not sure how to best write this down, but I feel that the docs as they currently exist could still use some improvement.

@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented Sep 22, 2020

@gvanrossum Thanks for the feedback! The docs here definitely needs refinement since #9238 also points out its incompleteness. I'll file a PR to update that and will request for your review there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify aliases vs variables
3 participants