Skip to content

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Mar 30, 2022

No description provided.

def bar(x: Optional[str]) -> Optional[int]: ...
def baz(x: None | str) -> None: ...

But the following is still necessary::
Copy link
Member

Choose a reason for hiding this comment

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

Is it? The only reason this would still be necessary is mypy bugs, and I don't think this doc should track exact mypy bugs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, in a way this doc must track bugs as it is a guide on how to write stubs. If it can't be used in stubs, we can't recommend to use it.

Copy link
Member

Choose a reason for hiding this comment

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

True, but this particular bug has been fixed, and I don't think we'll be able to keep this doc up to date with the exact mypy bugs that are still active. Perhaps we should just say that edge cases may not work with all type checkers yet, and link to https://github.com/python/mypy/labels/topic-pep-604

Copy link
Member

@AlexWaygood AlexWaygood Mar 30, 2022

Choose a reason for hiding this comment

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

There are (I think) 53 files in typeshed where we still have to import Union and/or Optional due to mypy bugs. Considering how large a repository typeshed is, that isn't so many — we can probably say that PEP 604 syntax can be safely used in nearly all situations now, but that a few bugs still remain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough, I'll send a PR tomorrow, unless someone else wants to improve the wording? Please feel free to commit to the branch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, we should make that a separate PR, as this is not related to type aliases.

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.

Maybe "variable aliases" instead of "regular aliases"?

_IntList = list[int]
_StrList: TypeAlias = list[str]

Type checkers should also accept regular module-level or class-level aliases,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Type checkers should also accept regular module-level or class-level aliases,
Type checkers should also accept module-level or class-level variable aliases,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that something more fitting than just "regular" would be a good idea, but "variable" doesn't really fit, in my opinion. For example, while class or function aliases could technically be considered variable aliases, it sounds a bit weird. Maybe we should just list the other cases? "Class, function, method, and (module- and class-level) attribute aliases".

Copy link
Member

Choose a reason for hiding this comment

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

I see your point. I think I'd still go with "variable aliases", but I don't object massively if you stick with "regular aliases" (I think "regular aliases" is probably better than listing them all out)

Type Aliases
------------

Use ``TypeAlias`` for type aliases (but not for regular aliases).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Use ``TypeAlias`` for type aliases (but not for regular aliases).
Use ``TypeAlias`` for type aliases (but not for variable aliases).

@srittau
Copy link
Collaborator Author

srittau commented Apr 5, 2022

Pingety pong.

@srittau srittau merged commit 5eed34c into python:master Apr 5, 2022
@srittau srittau deleted the type-alias branch April 5, 2022 17:09
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.

5 participants