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

Complete type annotations in pip/_internal/cli #10065

Merged
merged 21 commits into from
Jun 27, 2021

Conversation

DiddiLeija
Copy link
Member

This is the second part of my job made on #10018, where I must complete all the annotations from pip/_internal/cli.

This is the second part of my job made on pypa#10018, where I must complete all the annotations from `pip/_internal/cli`.
This is the news file for my pull request.
I just changed one function annotations, on line 121.
Just update the annotations according to the CI last failure.
I wanted to use "RequirementPreparer", not "RequirementParser".
@DiddiLeija
Copy link
Member Author

Hi. Now I have a huge question. On the last changes to req_command.py, I got this:

@@ -79,10 +79,10 @@ class SessionCommandMixin(CommandContextMixIn):
         return self._session
 
     def _build_session(
-        self, 
-        options: Values, 
-        retries: Optional[int] = None, 
-        timeout: Optional[int] = None
+        self,
+        options: Values,
+        retries: Optional[int] = None,
+        timeout: Optional[int] = None,
     ) -> PipSession:
         assert not options.cache_dir or os.path.isabs(options.cache_dir)
         session = PipSession(
@@ -235,7 +235,7 @@ class RequirementCommand(IndexGroupCommand):
         finder: PackageFinder,
         use_user_site: bool,
         download_dir: str = None,
-    ) -> RequirementPreparer: 
+    ) -> RequirementPreparer:
         """
         Create a RequirementPreparer instance for the given parameters.
         """
Error: The process '/opt/hostedtoolcache/Python/3.9.5/x64/bin/pre-commit' failed with exit code 1

I just can't see where my mistake is. Can somebody help me?

@DiddiLeija DiddiLeija changed the title Complete the annotations in pip/_internal/cli Complete the annotations from pip/_internal/cli Jun 14, 2021
@pfmoore
Copy link
Member

pfmoore commented Jun 14, 2021

You need to look a bit further up in the output:

Trim Trailing Whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing src/pip/_internal/cli/req_command.py

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted /home/runner/work/pip/pip/src/pip/_internal/cli/req_command.py
All done! ✨ 🍰 ✨
1 file reformatted, 90 files left unchanged.

So you had some trailing whitespace, and also your layout wasn't correct according to black.

Edit: Unfortunately, black doesn't tell you what was wrong, it just fixes it for you and leaves you to do a diff if you want to know. Don't get me started on this... 🙂

@DiddiLeija
Copy link
Member Author

Hum... this is confusing. So, what can I do now?

@pfmoore
Copy link
Member

pfmoore commented Jun 14, 2021

Fix the trailing whitespace issue and run black locally on your code, then push the changes. tox -e lint should do this for you locally. See [the docs](for the details).

@DiddiLeija
Copy link
Member Author

Fix the trailing whitespace issue and run black locally on your code, then push the changes. tox -e lint should do this for you locally.

Ok. I will be working on it for this week.

See [the docs](for the details).

Could you please give me the page? It can help me to solve this problem 😄.

@DiddiLeija
Copy link
Member Author

Well, if somebody else can test my problem at the same time than me, and finds where the problem is, please comment it. Also you can push the changes to my branch DiddiLeija:pip/_internal/cli-annotations-fixes-1.

@pfmoore
Copy link
Member

pfmoore commented Jun 14, 2021

Sorry! I messed up the Markdown for links. It's at https://pip.pypa.io/en/latest/development/getting-started/#running-linters

@DiddiLeija
Copy link
Member Author

Sorry! I messed up the Markdown for links. It's at https://pip.pypa.io/en/latest/development/getting-started/#running-linters

Oh, don't worry 😄.

@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 14, 2021

Ok. By now, I will be trying to solve this problem, but anyone else can try to help me.

(And thanks, @pfmoore. The article you commented was useful for me).

@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 14, 2021

After a long test (cloning my own fork, running git branch pip/internal/cli-annotations-fixes-1 to test the PR branch, then run tox -e lint), I finally got this results:

Administrador@PC MINGW32 ~/pip (main)
$ tox -e lint
lint installed: appdirs==1.4.4,cfgv==3.3.0,distlib==0.3.2,filelock==3.0.12,identify==2.2.10,nodeenv==1.6.0,pip==21.1.2,pre-commit==2.13.0,PyYAML==5.4.1,setuptools==57.0.0,six==1.16.0,toml==0.10.2,virtualenv==20.4.7,wheel==0.36.2
lint run-test-pre: PYTHONHASHSEED='604'
lint run-test: commands[0] | pre-commit run --all-files --show-diff-on-failure --hook-stage=manual
Check builtin type constructor use.......................................Passed
Check for added large files..............................................Passed
Check for case conflicts.................................................Passed
Check Toml...............................................................Passed
Check Yaml...............................................................Passed
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Forbid new submodules....................................................Passed
Trim Trailing Whitespace.................................................Passed
black....................................................................Passed
flake8...................................................................Passed
isort....................................................................Passed
mypy.....................................................................Passed
use logger.warning(......................................................Passed
check for eval().........................................................Passed
rst ``code`` is two backticks............................................Passed
NEWS fragment........................................(no files to check)Skipped
check-manifest...........................................................Passed
___________________________________ summary ___________________________________
  lint: commands succeeded
  congratulations :)

Administrador@PC MINGW32 ~/pip (main)
$

What do you think about this? Where is the problem?

@uranusjr
Copy link
Member

uranusjr commented Jun 15, 2021

     def _build_session(
-        self, 
-        options: Values, 
-        retries: Optional[int] = None, 
-        timeout: Optional[int] = None
+        self,
+        options: Values,
+        retries: Optional[int] = None,
+        timeout: Optional[int] = None,
     ) -> PipSession:

There’s a missing comma at the end of the timeout line

-    ) -> RequirementPreparer: 
+    ) -> RequirementPreparer:

There’s a trailing whitespace at the end (difficult to find if you just read the code on GitHub).

@DiddiLeija
Copy link
Member Author

Understood. Thank you very much. I will take that in count for today.

There were some previous errors with this, but now I fixed them.
It is not exactly a problem, it's just to pass the CI.
They fail on the CI checks.
@DiddiLeija
Copy link
Member Author

Done. The pre-commit test has passed. Now I will keep going with the pip/_intetnal/cli annotations - I almost finished.

Convert type commentaries into annotations.
@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 15, 2021

All the checks have passed. I finished all the pip/_internal/cli annotations. Now, feel free of merging this (because I can't do it by myself), and thanks to @pfmoore and @uranusjr for your help.

@DiddiLeija
Copy link
Member Author

Or maybe you can review the changes before merging.

DiddiLeija and others added 6 commits June 16, 2021 07:49
Fix also the original annotation instead of just copying it.

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Some of the annotations were incorrect.
It is "self._session: Optional[PipSession] = None" instead of "self._session = None # type: Optional[PipSession]".
They were imported but unused.
One of them was incorrect.
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 16, 2021

@uranusjr, @pfmoore and I were talking about Mypy is not giving any error message with some "evident" fails. You can see it on the last 2 reviews:

  1. At pip/_internal/cli/progress_bars.py, Mypy is OK with an incorrect annotation.
  2. At pip/_internal/cli/req_command.py, Mypy said nothing when I used min_update_interval_seconds: float = 60, which is supposed to be incorrect. (Edit: This is not actually a problem. Ignore it by now 😄).

However, I consider this is an issue with Mypy, not with Pip. If you want, I can open an issue with python/mypy to discuss this. If someone wants to do it, tell me first.

@DiddiLeija
Copy link
Member Author

Well. Everything's done by now.

If any @pypa member wants to merge this, just do it. Thank you for all your help.

@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 16, 2021

Hi @uranusjr, could you merge this PR? Or, can someone do it? Remember that I can't do it (GitHub restricted merging for me 😅)

About the Mypy issue, maybe we can open an issue over there and discuss on a larger way. (Or just update Mypy version to a new one, I don't know).

@DiddiLeija
Copy link
Member Author

Why is the docs/readthedocs.org:pip waiting for status to be reported, if anything is supposed to be OK?

@uranusjr
Copy link
Member

Checks sometimes fail like that, you know, networking glitches and things like that.

@uranusjr uranusjr closed this Jun 21, 2021
@uranusjr
Copy link
Member

Re-triggering builds.

@uranusjr uranusjr reopened this Jun 21, 2021
@DiddiLeija
Copy link
Member Author

Thanks. Now, we can safely merge.

@uranusjr uranusjr changed the title Complete the annotations from pip/_internal/cli Complete type annotations in pip/_internal/cli Jun 27, 2021
@uranusjr uranusjr merged commit 44b3c90 into pypa:main Jun 27, 2021
@DiddiLeija
Copy link
Member Author

Thanks @uranusjr!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants