Skip to content

Conversation

@donbarbos
Copy link
Contributor

@donbarbosdonbarbos commented Feb 7, 2025

@donbarbosdonbarbos changed the title Correct imports in Lib/_pyreplgh-129758: Correct imports in Lib/_pyreplFeb 7, 2025
Copy link
Member

@sobolevnsobolevn 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

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
ContributorAuthor

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:

importctypes# so i removed this import ... fromctypesimportStructure ... classCHAR_INFO(Structure): ... classKeyEvent(ctypes.Structure): # and fix here: ctypes.Structure -> Structure ...

@donbarbos
Copy link
ContributorAuthor

I have made the requested changes; please review again

@bedevere-app
Copy link

Thanks for making the requested changes!

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

@bedevere-appbedevere-appbot requested a review from sobolevnFebruary 7, 2025 11:19
Copy link
Member

@sobolevnsobolevn 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 .readlineimport_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
ContributorAuthor

@donbarbosdonbarbosFeb 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
ContributorAuthor

@donbarbosdonbarbosFeb 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

donbarbosand others added 5 commits February 7, 2025 11:34
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
Copy link
Member

@AA-TurnerAA-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

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.

donbarbosand others added 8 commits February 7, 2025 16:11
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@donbarbos
Copy link
ContributorAuthor

I have made the requested changes; please review again

@bedevere-app
Copy link

Thanks for making the requested changes!

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

@ambv
Copy link
Contributor

ambv commented Mar 20, 2025

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

@ambvambv closed this Mar 20, 2025
Sign up for freeto 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

@donbarbos@ambv@sobolevn@AA-Turner@hugovk