Skip to content

Nicer error messages for Union and Optional types #2561

Closed

Description

@FuegoFro

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.

Activity

  1. Nurdok commented on May 22, 2017

    @Nurdok
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions