-
Notifications
You must be signed in to change notification settings - Fork 3
add ty #306
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
Merged
add ty #306
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
89d94a7
add ty
pavelzw a54715a
introduce ty
pavelzw ea0ff71
WIP
pavelzw 275f1c3
Address some ty complaints.
kklein 867a959
Merge branch 'main' of github.com:Quantco/datajudge into ty
kklein 816c849
Don't expect children to implement retrieve and compare.
kklein 07e031d
use --no-progress
pavelzw 79ea6a8
Address some more ty complaints.
kklein 2596c26
Fix another ty complaint.
kklein 48b8c86
Add type annotation.
kklein 041ce7f
Remove type igores.
kklein b7d158c
Bring back instance caching
kklein 99222d3
Tell ty that the first argument to a method doesn't correspond to self.
kklein 2ccfe58
Remove some mypy hacks
kklein 226cef5
Update lock
kklein d700e93
Merge branch 'main' of github.com:Quantco/datajudge into ty
kklein 979f81b
Merge branch 'main' of github.com:Quantco/datajudge into ty
kklein b174f39
Add annotation and fix typo
kklein fd60cfb
Fix method references
kklein 309ddfa
Fix imports
kklein b27450a
Rework interfaces of select methods
kklein a58ac3c
Ensure that method overwrites are legitimate overwrites
kklein 3d2af01
Fix field references
kklein e043bec
Fix more method references.
kklein e1b733f
Bring back mypy
kklein a09f601
Use default environment for mypy
kklein 3750c16
Use updated lock
kklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,5 +1,3 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import abc | ||
| from collections.abc import Callable, Collection | ||
| from dataclasses import dataclass, field | ||
|
|
@@ -146,17 +144,24 @@ def __init__( | |
| not isinstance(output_processors, list) | ||
| ): | ||
| output_processors = [output_processors] | ||
| self.output_processors = output_processors | ||
| self.output_processors: list[OutputProcessor] | None = output_processors | ||
|
|
||
| self.cache_size = cache_size | ||
| self._setup_caching() | ||
|
|
||
| def _setup_caching(self): | ||
| # this has an added benefit of allowing the class to be garbage collected | ||
| # We don't use cache or lru_cache decorators since those would lead | ||
| # to class-based, not instance-based caching. | ||
| # | ||
| # Using this approach has the added benefit of allowing the class to be garbage collected | ||
| # according to https://rednafi.com/python/lru_cache_on_methods/ | ||
| # and https://docs.astral.sh/ruff/rules/cached-instance-method/ | ||
| self.get_factual_value = lru_cache(self.cache_size)(self.get_factual_value) # type: ignore[method-assign] | ||
| self.get_target_value = lru_cache(self.cache_size)(self.get_target_value) # type: ignore[method-assign] | ||
| self.get_factual_value: Callable[[Constraint, sa.engine.Engine], Any] = ( | ||
| lru_cache(self.cache_size)(self.get_factual_value) | ||
| ) | ||
| self.get_target_value: Callable[[Constraint, sa.engine.Engine], Any] = ( | ||
| lru_cache(self.cache_size)(self.get_target_value) | ||
| ) | ||
|
|
||
| def _check_if_valid_between_or_within( | ||
| self, | ||
|
|
@@ -176,13 +181,11 @@ def _check_if_valid_between_or_within( | |
| f"{class_name}. Use exactly either of them." | ||
| ) | ||
|
|
||
| # @lru_cache(maxsize=None), see _setup_caching() | ||
| def get_factual_value(self, engine: sa.engine.Engine) -> Any: | ||
| factual_value, factual_selections = self.retrieve(engine, self.ref) | ||
| self.factual_selections = factual_selections | ||
| return factual_value | ||
|
|
||
| # @lru_cache(maxsize=None), see _setup_caching() | ||
| def get_target_value(self, engine: sa.engine.Engine) -> Any: | ||
| if self.ref2 is None: | ||
| return self.ref_value | ||
|
|
@@ -235,14 +238,18 @@ def retrieve( | |
| self, engine: sa.engine.Engine, ref: DataReference | ||
| ) -> tuple[Any, OptionalSelections]: | ||
| """Retrieve the value of interest for a DataReference from database.""" | ||
| pass | ||
| raise NotImplementedError() | ||
|
|
||
| def compare(self, value_factual: Any, value_target: Any) -> tuple[bool, str | None]: | ||
| pass | ||
| raise NotImplementedError() | ||
|
|
||
| def test(self, engine: sa.engine.Engine) -> TestResult: | ||
| value_factual = self.get_factual_value(engine) | ||
| value_target = self.get_target_value(engine) | ||
| # ty can't figure out that this is a method and that self is passed | ||
| # as the first argument. | ||
| value_factual = self.get_factual_value(engine=engine) # type: ignore[missing-argument] | ||
|
||
| # ty can't figure out that this is a method and that self is passed | ||
| # as the first argument. | ||
| value_target = self.get_target_value(engine=engine) # type: ignore[missing-argument] | ||
| is_success, assertion_message = self.compare(value_factual, value_target) | ||
| if is_success: | ||
| return TestResult.success() | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Do we want this?