Skip to content

gh-129758: Correct imports in Lib/_pyrepl #129761

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

Closed
wants to merge 17 commits into from

Conversation

donBarbos
Copy link
Contributor

@donBarbos donBarbos commented Feb 7, 2025

@donBarbos donBarbos changed the title Correct imports in Lib/_pyrepl gh-129758: Correct imports in Lib/_pyrepl Feb 7, 2025
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I agree that changing if False to TYPE_CHECKING = False; if TYPE_CHECKING makes sense, because mypy better understands the second version.

See https://mypy-play.net/?mypy=latest&python=3.12&flags=strict%2Cwarn-unreachable&gist=ba9b71e677d20a0b4c1f78c731c0c0ea for if False:

main.py:4: error: Statement is unreachable  [unreachable]

And see https://mypy-play.net/?mypy=latest&python=3.12&flags=strict%2Cwarn-unreachable&gist=c84fabb19a5b4a92b6eee9656b978baa for if TYPE_CHECKING:

Succeeded!! (3383 ms)

So, basically - changing if False -> if TYPE_CHECKING is required to enable warn_unreachable = true.

But, I am against changing anything else. Let's no refactor other places, like moving imports or renaming things. It will just create more friction for no gain.

@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@donBarbos
Copy link
Contributor Author

donBarbos commented Feb 7, 2025

it's probably worth leaving the removal of warnings in readline.py, it's redundant here because this file already has lazy imports of warnings.

I also removed import code and wrote from code import InteractiveConsole in if TYPE_CHECKING: so as not to import code (if this's not a typecheck runtime). And I removed from .readline import _setup like lazy import because we already have global imports of .readline.

And the last one I removed import ctypes because after a few lines all the objects that are used in the code are imported separately and they are also accessed, like:

import ctypes # so i removed this import
...
from ctypes import Structure
...
class CHAR_INFO(Structure):
...
class KeyEvent(ctypes.Structure): # and fix here: ctypes.Structure -> Structure
...

@donBarbos
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2025

Thanks for making the requested changes!

@sobolevn: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from sobolevn February 7, 2025 11:19
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I've left several suggestions to minimize the final diff. Every line counts 😉
We should be very careful about what we change and what we don't change.

Thank you!

*,
future_flags: int = 0,
) -> None:
from .readline import _setup
Copy link
Member

Choose a reason for hiding this comment

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

Please, don't change this line.

Copy link
Contributor Author

@donBarbos donBarbos Feb 7, 2025

Choose a reason for hiding this comment

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

@sobolevn ok, but why? We already have import _setup on 34 line

Copy link
Member

Choose a reason for hiding this comment

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

In general, the default position is the status quo, you need to justify every change.

Copy link
Contributor Author

@donBarbos donBarbos Feb 7, 2025

Choose a reason for hiding this comment

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

I removed it because it duplicates imports. As I already said it is on line 34

@donBarbos donBarbos requested a review from sobolevn February 7, 2025 15:06
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

I agree that changing if False to TYPE_CHECKING = False; if TYPE_CHECKING makes sense, because mypy better understands the second version.

@sobolevn is it feasible to add a config option to mypy to have it recognise if False as the same as if TYPE_CHECKING?

We have the same idiom in several places, and if it leaks further then we will have a lot of useless module-level constants, whereas if False is optimised away by the interpreter. I'd prefer to wait for mypy to release a new version with this new option, rather than to change code here needlessly (it also attracts a lot of low value contributions because "<tool> has warnings" etc).

A

@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@donBarbos
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2025

Thanks for making the requested changes!

@sobolevn, @AA-Turner: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from AA-Turner February 7, 2025 16:24
@ambv
Copy link
Contributor

ambv commented Mar 20, 2025

Thanks, but we won't be taking this. This is churn.

@ambv ambv closed this Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants