-
Notifications
You must be signed in to change notification settings - Fork 281
Conversation
class PrecisionType(ColType): | ||
precision: int | ||
rounds: Union[bool, Unknown] = Unknown | ||
|
||
|
||
|
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.
[blackfmt] reported by reviewdog 🐶
class Connect: | ||
"""Provides methods for connecting to a supported database using a URL or connection dict.""" | ||
database_by_scheme: Dict[str, Database] |
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.
[blackfmt] reported by reviewdog 🐶
database_by_scheme: Dict[str, Database] | |
database_by_scheme: Dict[str, Database] |
def __init__(self, compiler: Compiler, gen: Generator): | ||
self.gen = gen | ||
self.compiler = compiler | ||
compiler: Compiler |
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.
[blackfmt] reported by reviewdog 🐶
compiler: Compiler | |
compiler: Compiler |
data_diff/databases/base.py
Outdated
@@ -522,7 +525,7 @@ def render_select(self, parent_c: Compiler, elem: Select) -> str: | |||
|
|||
def render_join(self, parent_c: Compiler, elem: Join) -> str: | |||
tables = [ | |||
t if isinstance(t, TableAlias) else TableAlias(t, parent_c.new_unique_name()) for t in elem.source_tables | |||
t if isinstance(t, TableAlias) else TableAlias(source_table_=t, name=parent_c.new_unique_name()) for t in elem.source_tables |
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.
[blackfmt] reported by reviewdog 🐶
t if isinstance(t, TableAlias) else TableAlias(source_table_=t, name=parent_c.new_unique_name()) for t in elem.source_tables | |
t if isinstance(t, TableAlias) else TableAlias(source_table_=t, name=parent_c.new_unique_name()) | |
for t in elem.source_tables |
select = ( | ||
f"SELECT {columns_str} FROM {self.compile(c.replace(in_select=True), elem.table)} GROUP BY {keys_str}{having_str}" | ||
f"SELECT {columns_str} FROM {self.compile(attrs.evolve(c, in_select=True), elem.table)} GROUP BY {keys_str}{having_str}" | ||
) |
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.
[blackfmt] reported by reviewdog 🐶
select = ( | |
f"SELECT {columns_str} FROM {self.compile(c.replace(in_select=True), elem.table)} GROUP BY {keys_str}{having_str}" | |
f"SELECT {columns_str} FROM {self.compile(attrs.evolve(c, in_select=True), elem.table)} GROUP BY {keys_str}{having_str}" | |
) | |
select = f"SELECT {columns_str} FROM {self.compile(attrs.evolve(c, in_select=True), elem.table)} GROUP BY {keys_str}{having_str}" |
@dataclass | ||
class Param(ExprNode, ITable): | ||
@attrs.define(eq=False, kw_only=True) | ||
class Param(ExprNode, ITable): # TODO: Unused? | ||
"""A value placeholder, to be specified at compilation time using the `cv_params` context variable.""" | ||
name: str |
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.
[blackfmt] reported by reviewdog 🐶
name: str | |
name: str |
@@ -31,19 +33,22 @@ class PriorityThreadPoolExecutor(ThreadPoolExecutor): | |||
|
|||
XXX WARNING: Might break in future versions of Python | |||
""" | |||
|
|||
def __init__(self, *args): |
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.
[blackfmt] reported by reviewdog 🐶
def __init__(self, *args): | |
def __init__(self, *args): |
class ThreadedYielder(Iterable): | ||
"""Yields results from multiple threads into a single iterator, ordered by priority. | ||
|
||
To add a source iterator, call ``submit()`` with a function that returns an iterator. | ||
Priority for the iterator can be provided via the keyword argument 'priority'. (higher runs first) | ||
""" | ||
_pool: ThreadPoolExecutor |
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.
[blackfmt] reported by reviewdog 🐶
_pool: ThreadPoolExecutor | |
_pool: ThreadPoolExecutor |
class ThreadedYielder(Iterable): | ||
"""Yields results from multiple threads into a single iterator, ordered by priority. | ||
|
||
To add a source iterator, call ``submit()`` with a function that returns an iterator. | ||
Priority for the iterator can be provided via the keyword argument 'priority'. (higher runs first) | ||
""" | ||
_pool: ThreadPoolExecutor | ||
_futures: deque | ||
_yield: deque = attrs.field(alias='_yield') # Python keyword! |
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.
[blackfmt] reported by reviewdog 🐶
_yield: deque = attrs.field(alias='_yield') # Python keyword! | |
_yield: deque = attrs.field(alias="_yield") # Python keyword! |
self.assertEqual( | ||
"`marine_mammals`.`walrus`", self.compiler.replace(root=False).compile(table("marine_mammals", "walrus")) | ||
"`marine_mammals`.`walrus`", compiler.compile(table("marine_mammals", "walrus")) | ||
) |
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.
[blackfmt] reported by reviewdog 🐶
self.assertEqual( | |
"`marine_mammals`.`walrus`", self.compiler.replace(root=False).compile(table("marine_mammals", "walrus")) | |
"`marine_mammals`.`walrus`", compiler.compile(table("marine_mammals", "walrus")) | |
) | |
self.assertEqual("`marine_mammals`.`walrus`", compiler.compile(table("marine_mammals", "walrus"))) |
`attrs` cannot use multiple inheritance when both parents introduce their attributes (as documented). Only one side can inherit the attributes, other bases must be pure interfaces/protocols. Reimplement the `ExprNode.type` via properties to exclude it from the sight of `attrs`.
We are going to do strict type checking. The default values of fields that clearly contradict the declared types is an error for MyPy and all other type checkers and IDEs. Remove the implicit behaviour and make nullable fields explicitly declared as such.
`attrs` is much more beneficial: * `attrs` is supported by type checkers, such as MyPy & IDEs * `attrs` is widely used and industry-proven * `attrs` is explicit in its declarations, there is no magic * `attrs` has slots But mainly for the first item — type checking by type checkers.
Since we now use `attrs` for some classes, let's use them for them all — at least those belonging to the same hierarchies. This will ensure that all classes are slotted and will strictly check that we define attributes properly, especially in cases of multiple inheritance. Except for Pydantic models and Python exceptions.
d02fad8
to
c8b1989
Compare
Accidentally closed by deleting the branch. Supersedes by #723. |
Short-term goal: resolve an issue where
runtype
cannot checkisinstance()
check, where the type is a string"Database"
coming fromCompilar.database: "Database"
.Technically, it is a
typing.ForwardRef[]
and must be resolved to actual classes on usage.attrs
andpydantic
do that.There is no way to convert it to a regular class, because there is still a circular class dependency
Database
<>Compiler
.Long-term goal: Since we are moving in the direction of strict type checking, let's make the first step: replace
runtype
with lots of implicit logic and not compatible with MyPy, withattrs
, which require explicitness and work fine with MyPy & IDEs.attrs
is much more beneficial:attrs
is supported by type checkers, such as MyPy & IDEsattrs
is widely used and industry-provenattrs
is explicit in its declarations, there is no magicattrs
has slotsBut mainly for the first item — type checking by type checkers.
And since we switch to
attrs
for already dataclass-like types, also expand it to all other (unannotated) classes to ensure proper attribute management in multiple inheritance.In particular, in the last commit, there are a few cases where the code was ambiguous and had to be resolved by minor remakes.
It is better to review commit-by-commit.