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

Warn about possibly infinite while #1007

Closed
orsinium opened this issue Nov 15, 2019 · 23 comments · Fixed by #1066
Closed

Warn about possibly infinite while #1007

orsinium opened this issue Nov 15, 2019 · 23 comments · Fixed by #1066
Assignees
Labels
help wanted Extra attention is needed level:starter Good for newcomers pr-available rule request Adding a new rule

Comments

@orsinium
Copy link
Collaborator

orsinium commented Nov 15, 2019

Rule request

Check that while True block has raise or return.

UPD: and break too.

Thesis

It's OK to not have them for CLI entry point, but in other cases, it can be an error. So, let's ask users explicitly noqa such cases to be sure that they really know what they're doing.

Reasoning

@orsinium orsinium added the rule request Adding a new rule label Nov 15, 2019
@sobolevn
Copy link
Member

break is also an option. I like this one!

@sobolevn sobolevn added this to the Version 0.13 milestone Nov 16, 2019
@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers labels Nov 16, 2019
@sobolevn sobolevn modified the milestones: Version 0.13, Version 0.15 Nov 16, 2019
@ragohin
Copy link
Contributor

ragohin commented Nov 18, 2019

Hi, I've been looking to contribute to this project and would like to try and implement this rule if nobody is on it!

@sobolevn
Copy link
Member

Sure, I would be happy to answer your questions! Thanks!

@ragohin
Copy link
Contributor

ragohin commented Dec 4, 2019

Hi there! After perusing through the source code and the tutorial documentation, I was thinking that this rule would best fit in wemake_python_styleguide\visitors\ast\loops.py. Does this seem like a good place to start?

@sobolevn
Copy link
Member

sobolevn commented Dec 4, 2019

Yes, it does! Do you want to take this one?

Feel free to ask for help! 👍

@ragohin
Copy link
Contributor

ragohin commented Dec 5, 2019

Sorry about the delayed responses on this issue! I'll work on this implementation tomorrow. Thanks!

@ragohin
Copy link
Contributor

ragohin commented Dec 6, 2019

I was able to successfully call "make test" without any errors when I first cloned the repo, but after implemented a few changes, I go the following error complaining that "no shebang is present:"

no_shebang

I thought that this may have been caused by the changed I introduced to the source code, but after recloning the repo, the same error messages persist.

I could not find much specific help on this issue online and was wondering if you have run into this? I am running on Ubuntu 18.04 by the way. Thanks!

@sobolevn
Copy link
Member

sobolevn commented Dec 6, 2019

This warning means that you file has executable rights, but does not have a sebang #!/... in its source code. And since these files should be executable at all, I guess the problem is inside your machine.

Check file rights with ls -alh, they should not have +x for all categories.

You can also send me git status output, it might help.

@ragohin
Copy link
Contributor

ragohin commented Dec 7, 2019

Ah yes, chmod did the trick to fix the file rights. Thanks!

@ragohin
Copy link
Contributor

ragohin commented Dec 9, 2019

I'm a bit confused by the error "WPS214 Found too many methods: 9" error that is printed out when flake8 runs in wemake_python_styleguide\visitors\ast\loops.py. It seems like you've talked about this in a previous issue #678.

So, do I have to reduce the number of methods that I have added to the WrongLoopVisitor class? I added two functions to this class, one for parsing a node to check if it violates the rule and a helper function. However, this error was still thrown when I did not have a helper function (the number of methods was 8).

@ragohin
Copy link
Contributor

ragohin commented Dec 9, 2019

I created a new pull request just in case you need access to see the specific code I am referring to. Thanks!

@ragohin
Copy link
Contributor

ragohin commented Dec 9, 2019

It seem like these functions in WrongLoopVisitor class are cluttering things up and need to be reused or moved.

trouble_functions

However, I cannot figure out how to change/move them without breaking other things in the code.

@sobolevn
Copy link
Member

sobolevn commented Dec 9, 2019

Move them to logic/

@ragohin
Copy link
Contributor

ragohin commented Dec 10, 2019

Great thanks!

I moved those functions to logic and everything seems to be working, but there is an issue right now with running pytest. The rule, as defined, raises the violation in any "while True:" loop that does not contain a break, return, or raise, but there are instances of these loops in some of the other test files like the one below (wemake-python-styleguide/tests/test_visitors/test_ast/test_loops/test_loops/test_lambda_in_loop.py).

Screen Shot 2019-12-09 at 8 48 38 PM

It seems like there are two options:

  1. add a break to these tests
  2. change the way the infinite while loop rule is defined so that these instances don't fail

I'm leaning towards (1) because it seems like the while loops in these test cases would be incorrect because they don't necessarily exit. Does this seem like the best approach?

@ragohin
Copy link
Contributor

ragohin commented Dec 10, 2019

Also, what exactly would an integration test to add to tests/fixtures/noqa.py look like? I'm a bit confused on what I should add here. Like I probably shouldn't just add "while True:" because it might hang forever.

@ragohin
Copy link
Contributor

ragohin commented Dec 10, 2019

I think I figured it out. I removed those lines from test_lambda_in_loop.py because they are actual violations of the infinite loop rule. All of the requirements have been satisfied except for the adding of an integration test in noqa.py because I could not figure out how to include an infinite loop without pytest failing when running this file. I'll submit another pull request right now, but please let me know if it is possible to add an integration test for this. Thanks!

@pandaseal
Copy link
Contributor

@ragohin may I ask how you fixed the EXE002 error exactly? I have just forked the project and get this error the first time i try to run make test.

I run Ubuntu 16.04 but we get the same error in Ubuntu 18.04.

@sobolevn
Copy link
Member

@pandaseal this is related to your folder structure. Run ls -alh and then fix file permissions if you have any. That should solve it.

@pandaseal
Copy link
Contributor

@sobolevn should I do it manually for every file that fails? I do not really know how to go about all of it... Any tips?

@sobolevn
Copy link
Member

It really dependends on your problem and your OS. I don't think that I can help without any further information. You can also just ignore this issue for now. It works on CI correctly.

@pandaseal
Copy link
Contributor

pandaseal commented Feb 25, 2020

@sobolevn We fixed it. Thanks for your help.

If anyone else has this problem, this was the solution:

  • System: Ubuntu 16.04 WSL on Windows 10
  • Problem: Windows overwrote the permissions of the WSL when the repo was located in the Windows partition (/mnt), changing the permissions did not work. Here is why changing permissions wouldn't work.
  • Solution: Clone the repo directly onto the home (ie. do cd and then clone the repo) of the WSL.

@sobolevn
Copy link
Member

@pandaseal you can submit this to CONTRIBUTING.md

@pandaseal
Copy link
Contributor

@sobolevn should I create an issue where we can discuss this further? For example where the information should be added in CONTRIBUTING.md and on which level it should be described? (I mean, at this point is not really relevant for this issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed level:starter Good for newcomers pr-available rule request Adding a new rule
Projects
None yet
4 participants