Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add machinery for marking places we subvert the type system (#5467)
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 runtype 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.
- Loading branch information
Showing
8 changed files
with
80 additions
and
37 deletions.
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