Skip to content
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

Invalid Python in test cases #687

Closed
spkersten opened this issue May 18, 2015 · 9 comments
Closed

Invalid Python in test cases #687

spkersten opened this issue May 18, 2015 · 9 comments

Comments

@spkersten
Copy link
Contributor

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.

@JukkaL JukkaL added the bug mypy got something wrong label May 19, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented May 19, 2015

Yeah, this is unfortunate.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 3, 2016

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

@JukkaL JukkaL added the easy label Jun 3, 2016
@ArgentFalcon
Copy link

I'm looking into this

@ArgentFalcon
Copy link

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?

@gvanrossum
Copy link
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).

@ArgentFalcon
Copy link

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

@ArgentFalcon
Copy link

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

@hauntsaninja
Copy link
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.

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 22, 2023

I think that this was addressed in #14166.

@JukkaL JukkaL closed this as completed Apr 22, 2023
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

7 participants