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

addressing issue 114: await async rule does not account for decorators #150

Merged
merged 6 commits into from
Nov 6, 2020

Conversation

haroldopsf
Copy link
Contributor

Summary

addressing issue 114: await async rule does not account for decorators

Test Plan

tox -e py38 -- fixit.tests.AwaitAsyncCallRule

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 16, 2020
@Kronuz
Copy link
Contributor

Kronuz commented Oct 19, 2020

Does the expected replacement you added to your tests have some errors? I'm using this instead:

        Invalid(
            """
            class Foo:
                @classmethod
                async def _method(cls): pass
            Foo._method()
            """,
            expected_replacement="""
            class Foo:
                @classmethod
                async def _method(cls): pass
            await Foo._method()
            """,
        ),
        Invalid(
            """
            class Foo:
                @staticmethod
                async def _method(): pass
            Foo._method()
            """,
            expected_replacement="""
            class Foo:
                @staticmethod
                async def _method(): pass
            await Foo._method()
            """,
        ),

However, those tests pass even without chaning _is_awaitable_callable(). Please verify and advise.

@haroldopsf
Copy link
Contributor Author

thanks @Kronuz for your correction. Unfortunately I cannot verify or try my changes.
When I run:
python3 -m fixit.common.generate_pyre_fixtures AwaitAsyncCallRule

I get:

(fixit-env) haroldo@KTM:~/github/Fixit$ python3 -m fixit.common.generate_pyre_fixtures AwaitAsyncCallRule
/usr/lib/python3.6/runpy.py:125: RuntimeWarning: 'fixit.common.generate_pyre_fixtures' found in sys.modules after import of package 'fixit.common', but prior to execution of 'fixit.common.generate_pyre_fixtures'; this may result in unpredictable behaviour
warn(RuntimeWarning(msg))
Starting pyre server
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/haroldo/github/Fixit/fixit/common/generate_pyre_fixtures.py", line 120, in
gen_types(cast(CstLintRule, rule), fixture_path)
File "/home/haroldo/github/Fixit/fixit/common/generate_pyre_fixtures.py", line 84, in gen_types
gen_types_for_test_case(source_code=valid_tc.code, dest_path=path)
File "/home/haroldo/github/Fixit/fixit/common/generate_pyre_fixtures.py", line 60, in gen_types_for_test_case
raise PyreQueryError(cmd, data["error"])
main.PyreQueryError: Unable to infer types from temporary file. Command pyre query "types(path='/home/haroldo/github/Fixit/fixit/tests/fixtures/await_async_call/tmp_95f6o54.py')" returned with the following message: Not able to get lookups in:
/home/haroldo/github/Fixit/fixit/tests/fixtures/await_async_call/tmp_95f6o54.py.

Any ideas why the generate_python_fixtures doesn't run on this code?
I'm updating the patch anyway, but would appreciate some help getting the tool to run

thanks

@Kronuz
Copy link
Contributor

Kronuz commented Oct 19, 2020

That's the command I used to generate the fixtures, it should be working. Try removing and re-creating the virtual environment. Other than that, maybe @jimmylai can shed some light on it.

@jimmylai
Copy link
Contributor

It works for me as the following output. Your dev environment has some issues. You can probably try to delete your venv and follow the steps in README to create.

Fixit % python3 -m fixit.common.generate_pyre_fixtures AwaitAsyncCallRule
/opt/homebrew/Cellar/python37/3.7.5_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py:125: RuntimeWarning: 'fixit.common.generate_pyre_fixtures' found in sys.modules after import of package 'fixit.common', but prior to execution of 'fixit.common.generate_pyre_fixtures'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
Starting pyre server
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_0.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_1.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_2.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_3.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_4.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_VALID_5.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_0.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_1.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_2.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_3.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_4.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_5.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_6.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_7.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_8.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_9.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_10.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_11.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_12.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_13.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_14.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_15.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_16.json
Writing output to /Users/jimmylai/github/Fixit/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_17.json

To unblock your work, you also can use my generated fixture.
https://gist.github.com/jimmylai/98cd429db6362ffd84d3dad892ec0606
With those needed fixture files in fixit/tests/fixtures/await_async_call/, all tests passed.

(fixit-env) jimmylai@jimmylai-mbp Fixit % tox -e py38 -- fixit.tests.AwaitAsyncCallRule


GLOB sdist-make: /Users/jimmylai/github/Fixit/setup.py
py38 inst-nodeps: /Users/jimmylai/github/Fixit/.tox/.tmp/package/2/fixit-0.1.1.zip
py38 installed: alabaster==0.7.12,appdirs==1.4.4,appnope==0.1.0,argon2-cffi==20.1.0,async-generator==1.10,attrs==20.2.0,Babel==2.8.0,backcall==0.2.0,black==20.8b1,bleach==3.2.1,certifi=
=2020.6.20,cffi==1.14.3,chardet==3.0.4,click==7.1.2,codecov==2.1.9,coverage==5.3,decorator==4.4.2,defusedxml==0.6.0,diff-cover==4.0.1,distlib==0.3.1,docutils==0.16,entrypoints==0.3,file
lock==3.0.12,fixit @ file:///Users/jimmylai/github/Fixit/.tox/.tmp/package/2/fixit-0.1.1.zip,flake8==3.8.3,idna==2.10,imagesize==1.2.0,inflect==4.1.0,ipykernel==5.3.4,ipython==7.18.1,ip
ython-genutils==0.2.0,ipywidgets==7.5.1,isort==5.5.3,jedi==0.17.2,Jinja2==2.11.2,jinja2-pluralize==0.3.0,jsonschema==3.2.0,jupyter==1.0.0,jupyter-client==6.1.7,jupyter-console==6.2.0,ju
pyter-core==4.6.3,jupyterlab-pygments==0.1.1,libcst==0.3.10,MarkupSafe==1.1.1,mccabe==0.6.1,mistune==0.8.4,mypy-extensions==0.4.3,nbclient==0.5.0,nbconvert==6.0.6,nbformat==5.0.7,nbsphi
nx==0.7.1,nest-asyncio==1.4.0,notebook==6.1.4,packaging==20.4,pandocfilters==1.4.2,parso==0.7.1,pathspec==0.8.0,pexpect==4.8.0,pickleshare==0.7.5,pluggy==0.13.1,prometheus-client==0.8.0
,prompt-toolkit==3.0.7,psutil==5.7.2,ptyprocess==0.6.0,py==1.9.0,pycodestyle==2.6.0,pycparser==2.20,pyflakes==2.2.0,Pygments==2.7.1,pyparsing==2.4.7,pyre-check==0.0.41,pyre-extensions==
0.0.18,pyrsistent==0.17.3,python-dateutil==2.8.1,pytz==2020.1,pywatchman==1.4.1,PyYAML==5.3.1,pyzmq==19.0.2,qtconsole==4.7.7,QtPy==1.9.0,regex==2020.7.14,requests==2.24.0,Send2Trash==1.
5.0,six==1.15.0,snowballstemmer==2.0.0,Sphinx @ git+https://github.com/jimmylai/sphinx.git@971540b26a8412399a9face3752cafc4519ff748,sphinx-rtd-theme==0.5.0,sphinxcontrib-applehelp==1.0.
2,sphinxcontrib-devhelp==1.0.2,sphinxcontrib-htmlhelp==1.0.3,sphinxcontrib-jsmath==1.0.1,sphinxcontrib-qthelp==1.0.3,sphinxcontrib-serializinghtml==1.1.4,terminado==0.9.1,testpath==0.4.
4,toml==0.10.1,tornado==6.0.4,tox==3.20.0,traitlets==5.0.4,typed-ast==1.4.1,typing-extensions==3.7.4.3,typing-inspect==0.6.0,urllib3==1.25.10,virtualenv==20.0.31,wcwidth==0.2.5,webencod
ings==0.5.1,widgetsnbextension==3.5.1
py38 run-test-pre: PYTHONHASHSEED='2696143614'
py38 run-test: commands[0] | python -m unittest fixit.tests.AwaitAsyncCallRule
........................
----------------------------------------------------------------------
Ran 24 tests in 0.338s

OK
________________________________________________________________________________________ summary ________________________________________________________________________________________
  py38: commands succeeded
  congratulations :)

Copy link
Contributor

@jimmylai jimmylai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jimmylai jimmylai merged commit 6e662b2 into Instagram:master Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants