Skip to content

What is the recommended way to deal with platform-specific imports? #9062

Answered by erictraut
Bruntaz asked this question in Q&A
Discussion options

You must be logged in to vote

Your refactored code is on the right path, but you're using a conditional expression form that type checkers do not recognize. If you change it to if sys.platform == "win32" or sys.platform == "cygwin":, you'll get the effect you're looking for. Type checkers are required by the typing standard to recognize a few specific conditional forms when checking for platforms and Python versions. If you use some alternative form, it won't be recognized.

As an alternative, you can add a # pyright: ignore[reportMissingModuleSource] to suppress the warning on that line. Or you can add a # pyright: reportMissingModuleSource=false at the top of the file to suppress it for the entire file.

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@Bruntaz
Comment options

@erictraut
Comment options

@Bruntaz
Comment options

@erictraut
Comment options

@Bruntaz
Comment options

Answer selected by Bruntaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants