Skip to content

Nicer error messages for Union and Optional types #2561

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
FuegoFro opened this issue Dec 13, 2016 · 1 comment
Closed

Nicer error messages for Union and Optional types #2561

FuegoFro opened this issue Dec 13, 2016 · 1 comment

Comments

@FuegoFro
Copy link
Contributor

The error message you get when something is Optional and you try to access it isn't as friendly as it might be (with --strict-optional). Eg if I have

def foo(s: Optional[str]) -> None:
    print(s.count('a'))

It says error: Some element of union has no attribute "count".

It would be nicer if it said something like Variable 's' may be None or something a bit special cased to the Union with None case.

Generalizing a bit, one could imagine better handling of Unions in general by specifying what is in the Union or even which types in the Unions are causing the issue.

@Nurdok
Copy link
Contributor

Nurdok commented May 22, 2017

I'm looking at working on this.

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

4 participants