Skip to content

Invalid Python in test cases #687

Closed
Closed

Description

@spkersten

Many test cases (>100) contain invalid Python code like this,

a = A()

class A: pass

where a name is referenced before it is bound.

This impedes solving #686.

Activity

  1. JukkaL commented on May 19, 2015

    @JukkaL
    Collaborator

    Yeah, this is unfortunate.

  2. JukkaL commented on Jun 3, 2016

    @JukkaL
    Collaborator

    Many of these cases can likely be found using the test data parser used for running test cases and regular expressions.

  3. ArgentFalcon commented on Jun 3, 2016

    @ArgentFalcon

    I'm looking into this

  4. ArgentFalcon commented on Jun 3, 2016

    @ArgentFalcon

    Do we want blanket fixes over all tests so that names are only referenced after they are bound?
    Or do we want to leave some tests incorrect so that we can validate that mypy correctly errors for them?

    Also, @spkersten, can you point me to your changes that enable mypy to detect this issue?

  5. gvanrossum commented on Jun 3, 2016

    @gvanrossum
    Member

    I'd define a few separate tests that check for various kinds of forward references (e.g. module, class, function, nested class, type variable, type alias, other kind of variable). Though it's possible that mypy needs to be fixed first to actually error out on them. It's also possible that we should fix the tests without fixing this in mypy (maybe fixing this in mypy is tricky, and of course it must still support forward references from type comments or type annotations in string literals).

  6. ArgentFalcon commented on Jun 3, 2016

    @ArgentFalcon

    Going by @gvanrossum comment, it seems that we want to make a separate set of tests to test forward references. Therefore I will move forward on my quest to fix all mis-referenced tests I can find

  7. ArgentFalcon commented on Jun 4, 2016

    @ArgentFalcon

    So right now I'm writing a test suite that tries to exec all the test cases and report their failure.
    My next task will be blacklisting the test-files that shouldn't be run (testing the pyi stuff), as well as
    the files/test cases that should intentionally fail

  8. hauntsaninja commented on Sep 25, 2022

    @hauntsaninja
    Collaborator

    yup, still open, feel free to work on it. see https://github.com/python/mypy/blob/master/CONTRIBUTING.md#first-time-contributors

    You do not need to ask for permission to work on any of these issues. Just fix the issue yourself, try to add a unit test and open a pull request.

  9. JukkaL commented on Apr 22, 2023

    @JukkaL
    Collaborator

    I think that this was addressed in #14166.

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