Skip to content

Prefer os.path.exists over os.stat try-catch#2463

Open
Avasam wants to merge 1 commit intomhammond:mainfrom
Avasam:os.path.exists-over-os.stat
Open

Prefer os.path.exists over os.stat try-catch#2463
Avasam wants to merge 1 commit intomhammond:mainfrom
Avasam:os.path.exists-over-os.stat

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Jan 17, 2025

Makes checking the existence of a path more idiomatic.
Reduces use of try-catch for logical flow.
Simplifies some code.
Solves a few "possibly unbound/undefined" variables as seen by type-checkers.

@@ -18,13 +18,15 @@

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This module has been marked as deprecated for the past 18 years. A comment set it for removal around "2009 or so".
Would it be better to just remove it?

However it is used by win32/scripts/regsetup.py (checks the registry after Python registration). I'm not sure about a modern use case for the regsetup.py script either.

Fixes a few reportPossiblyUnboundVariable and possibly-undefined
@Avasam Avasam force-pushed the os.path.exists-over-os.stat branch from fd951fb to 40caf46 Compare January 17, 2025 02:58
@Avasam Avasam requested a review from mhammond May 30, 2025 19:14
return 1
except OSError as details:
return 0
return os.path.exists(fname)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: remove this helper function entirely, it's in a scripts file, it's not public API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant