-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Support in/not in tests on sys.platform #21913
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,6 +474,82 @@ reveal_type(x) # N: Revealed type is "builtins.str" | |
| [builtins fixtures/ops.pyi] | ||
| [out] | ||
|
|
||
| [case testCustomSysPlatformMembershipTuple] | ||
| # flags: --platform linux | ||
| import sys | ||
| if sys.platform in ('linux', 'darwin'): | ||
| x = "foo" | ||
| else: | ||
| x = 3 | ||
| reveal_type(x) # N: Revealed type is "builtins.str" | ||
|
|
||
| if sys.platform not in ('win32', 'cygwin'): | ||
| y = "foo" | ||
| else: | ||
| y = 3 | ||
| reveal_type(y) # N: Revealed type is "builtins.str" | ||
|
|
||
| if sys.platform in ('win32', 'cygwin'): | ||
| z = "foo" | ||
| else: | ||
| z = 3 | ||
| reveal_type(z) # N: Revealed type is "builtins.int" | ||
|
|
||
| if sys.platform not in ('linux', 'darwin'): | ||
| w = "foo" | ||
| else: | ||
| w = 3 | ||
| reveal_type(w) # N: Revealed type is "builtins.int" | ||
| [builtins fixtures/ops.pyi] | ||
| [out] | ||
|
|
||
| [case testCustomSysPlatformMembershipSet] | ||
| # flags: --platform linux | ||
| import sys | ||
| if sys.platform in {'linux', 'darwin'}: | ||
| x = "foo" | ||
| else: | ||
| x = 3 | ||
| reveal_type(x) # N: Revealed type is "builtins.str" | ||
|
|
||
| if sys.platform not in {'linux', 'darwin'}: | ||
| y = "foo" | ||
| else: | ||
| y = 3 | ||
| reveal_type(y) # N: Revealed type is "builtins.int" | ||
| [builtins fixtures/set.pyi] | ||
| [out] | ||
|
|
||
| [case testSysPlatformMembershipUnknown] | ||
| import sys | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we specify --platform in this test as well? it's a little confusing otherwise. e.g. you could imagine a future mypy is smart enough to do the right thing for partially known containers (also i prefer the test style above with the reveal_type's, it's more robust to changes to what bindings mypy allows) |
||
|
|
||
| platform = sys.platform | ||
| if sys.platform in ('linux', platform): | ||
| def f() -> int: return 0 | ||
| else: | ||
| def f() -> str: return '' # E: All conditional function variants must have identical signatures \ | ||
| # N: Original: \ | ||
| # N: def f() -> int \ | ||
| # N: Redefinition: \ | ||
| # N: def f() -> str | ||
| [builtins fixtures/ops.pyi] | ||
| [out] | ||
|
|
||
| [case testSysPlatformMembershipListIsUnknown] | ||
| # flags: --platform linux | ||
| import sys | ||
|
|
||
| if sys.platform in ['linux', 'darwin']: | ||
| def f() -> int: return 0 | ||
| else: | ||
| def f() -> str: return '' # E: All conditional function variants must have identical signatures \ | ||
| # N: Original: \ | ||
| # N: def f() -> int \ | ||
| # N: Redefinition: \ | ||
| # N: def f() -> str | ||
| [builtins fixtures/list.pyi] | ||
| [out] | ||
|
|
||
| [case testShortCircuitInExpression] | ||
| import typing | ||
| def make() -> bool: pass | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not have ListExpr
the related test is confusing, would be clearer as
cast(list[str], [])or inside a function