Skip to content

Implement Optional[T] as an alias for Union[T, None] #477

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

Closed
JukkaL opened this issue Oct 12, 2014 · 1 comment
Closed

Implement Optional[T] as an alias for Union[T, None] #477

JukkaL opened this issue Oct 12, 2014 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 12, 2014

In preparation for strict checking of None values, Optional[T] should be an alias for Union[T, None] (for arbitrary T).

There are at least two valid ways to implement this:

  1. Special case Optional[T] in the semantic analyzer.
  2. Support generic type aliases of form Optional = Union[T, None], and use this to define Optional.

In the latter case, the fact that Optional takes a type argument would be inferred from the right hand side -- I assume that T is a free (unbound) type variable, so it is inferred as an argument of the left hand side. The second case is also complicated by the fact that the result of Union[...] should support indexing.

The first approach is okay as well, even though eventually we might want generic type aliases.

In either case, the typing module must be modified as well so that Optional can be used at runtime.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Feb 8, 2015

As we currently don't have precise type checking of None values, Optional[t] would be an alias for t. That is, it's mostly for documentation for now -- and to make it easier to switch to better None type checking in the (hopefully near) future.

@JukkaL JukkaL closed this as completed in f6cd1d6 Feb 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant