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
Add machinery for marking places we subvert the type system #5467
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e21f6a
Add machinery for marking places we subvert the type system
msullivan 35af440
Some cleanups
msullivan 049d88c
Get rid of _name in MypyFile
msullivan 07caba8
Merge branch 'master' into bogus
msullivan e29c39c
Switch to specifying mypy_extensions==0.4.0
msullivan 838178d
Add mypy_extensions to setup
msullivan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""A Bogus[T] type alias for marking when we subvert the type system | ||
|
||
We need this for compiling with mypyc, which inserts runtime | ||
typechecks that cause problems when we subvert the type system. So | ||
when compiling with mypyc, we turn those places into Any, while | ||
keeping the types around for normal typechecks. | ||
|
||
Since this causes the runtime types to be Any, this is best used | ||
in places where efficient access to properties is not important. | ||
For those cases some other technique should be used. | ||
""" | ||
|
||
from mypy_extensions import FlexibleAlias | ||
from typing import TypeVar, Any | ||
|
||
T = TypeVar('T') | ||
|
||
SUPPRESS_BOGUS_TYPES = False | ||
if SUPPRESS_BOGUS_TYPES: | ||
Bogus = FlexibleAlias[T, Any] | ||
else: | ||
Bogus = FlexibleAlias[T, T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[mypy] | ||
disallow_untyped_defs = True | ||
disallow_subclassing_any = True | ||
warn_no_return = True | ||
strict_optional = True | ||
no_implicit_optional = True | ||
disallow_any_generics = True | ||
disallow_any_unimported = True | ||
warn_redundant_casts = True | ||
warn_unused_configs = True | ||
always_true = SUPPRESS_BOGUS_TYPES | ||
|
||
# needs py2 compatibility | ||
[mypy-mypy.test.testextensions] | ||
disallow_untyped_defs = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am a bit surprised the
Bogus
is needed here, and not inmake_normalized
, where the actual hack happens. But most probably I am just missing something.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.
The crash does indeed happen in
make_normalized
, when it tries to coerce the arguments to the type required by__init__