Skip to content

Prohibit use of names in annotations that are undefined in runtime #3088

Closed

Description

@pkch

This type checks, but crashes in runtime with NameError:

class A:
    def f(x: A) -> None:
        pass

I think it's better if mypy reported an error Name "A" should be a forward reference.

Activity

  1. gvanrossum commented on Mar 30, 2017

    @gvanrossum
    Member

    Oh, that's weird. I didn't even know mypy accepts that! Agreed it would be better to flag as error. (Outside stubs, and not in type comments of course.)

  2. changed the title [-]Prohibit use of names undefined in runtime[/-] [+]Prohibit use of names in annotations that are undefined in runtime[/+] on Sep 18, 2017
  3. emmatyping commented on Nov 4, 2017

    @emmatyping
    Member

    Closing as a duplicate in favor of #948, which has a bit more information.

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