-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type checking to Continuous Integration for Snowfakery (#740)
* Type checking and some CI upgrades
- Loading branch information
Paul Prescod
committed
Oct 7, 2022
1 parent
2f589a4
commit db6274a
Showing
12 changed files
with
82 additions
and
89 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 |
---|---|---|
|
@@ -11,3 +11,5 @@ exclude_lines = | |
raise AssertionError | ||
def __repr__ | ||
def __str__ | ||
if T.TYPE_CHECKING | ||
if TYPE_CHECKING |
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,14 @@ | ||
[tool.pyright] | ||
include = [ | ||
"snowfakery/utils/*", | ||
"snowfakery/tools/*", | ||
"snowfakery/__init__.py", | ||
"snowfakery/__main__.py", | ||
"snowfakery/cci_mapping_files/post_processes.py", | ||
"snowfakery/data_gen_exceptions.py", | ||
"snowfakery/salesforce.py", | ||
"snowfakery/standard_plugins/SnowfakeryVersion.py", | ||
"snowfakery/standard_plugins/__init__.py", | ||
"snowfakery/standard_plugins/base64.py", | ||
"snowfakery/object_rows.py", | ||
] |
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,24 @@ | ||
import contextlib | ||
from typing import Callable, ContextManager, Iterator, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
# until https://github.com/agronholm/typeguard/issues/115 is fully fixed | ||
# or typeguard is removed, we need this hack. | ||
|
||
# The fix is on typeguard/master and should be merged in Typeguard 3.0 | ||
# | ||
# We need this feature to be moved from UNRELEASED to RELEASED: | ||
# | ||
# Changed the import hook to append @typechecked to the | ||
# decorator list instead of inserting it as the first decorator | ||
# (fixes type checking inconsistencies with mypy regarding at least | ||
# @contextmanager, probably others too) | ||
|
||
|
||
def contextmanager( | ||
func: Callable[..., Iterator[T]] | ||
) -> Callable[..., ContextManager[T]]: | ||
result = contextlib.contextmanager(func) | ||
result.__annotations__ = {**func.__annotations__, "return": ContextManager[T]} | ||
return result |
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 |
---|---|---|
@@ -1,69 +1,4 @@ | ||
""" Benchmarking tool for the RowHistory backing database""" | ||
|
||
from snowfakery.row_history import RowHistory | ||
from snowfakery.object_rows import RowHistoryCV | ||
from time import time | ||
|
||
COUNT = 200_000 | ||
|
||
|
||
def main(count): | ||
rh: RowHistory = RowHistory() | ||
RowHistoryCV.set(rh) | ||
start = time() | ||
for i in range(0, COUNT, 4): | ||
rh.save_row( | ||
"table", | ||
None, | ||
{ | ||
"id": i, | ||
"blah": "blah", | ||
}, | ||
) | ||
|
||
rh.save_row( | ||
"table", | ||
"Nicknamed", | ||
{ | ||
"id": i + 1, | ||
"blah": "blah", | ||
}, | ||
) | ||
|
||
rh.save_row( | ||
"table", | ||
"Nicknamed2", | ||
{ | ||
"id": i + 2, | ||
"blah": "blah", | ||
}, | ||
) | ||
|
||
if i % 1000 == 0: | ||
nickname = "Sparse" | ||
else: | ||
nickname = "Unused" | ||
|
||
rh.save_row( | ||
"table", | ||
nickname, | ||
{ | ||
"id": i + 3, | ||
"blah": "blah", | ||
}, | ||
) | ||
|
||
end = time() | ||
print("Saved", end - start) | ||
start = time() | ||
for i in range(0, COUNT): | ||
rh.load_row("table", i) | ||
assert rh.random_row_reference("table", "current-iteration", False).blah | ||
assert rh.random_row_reference("Nicknamed", "current-iteration", False).blah | ||
assert rh.random_row_reference("Nicknamed2", "current-iteration", False).blah | ||
assert rh.random_row_reference("Sparse", "current-iteration", False).blah | ||
end = time() | ||
print("Loaded", end - start) | ||
|
||
|
||
main(COUNT) | ||
# Deleted after 2f589a4a44f7ff8e9a4650e978d24839d47f61d9 | ||
# Go back to that PR if you want that code back. |
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