Conversation
📝 Docs previewLast commit c49bf7f at: https://4d2e1793.sqlmodel.pages.dev |
…rs are before it (invalid-legacy-positional-parameter)
| t_type = f"_T{i}" | ||
| t_var = f"_TCCA[{t_type}]" | ||
| arg = Arg(name=f"__ent{i}", annotation=t_var) | ||
| arg = Arg(name=f"_ent{i}", annotation=t_var) |
There was a problem hiding this comment.
ty complaints with:
warning[invalid-legacy-positional-parameter]: Invalid use of the legacy convention for positional-only parameters
--> sqlmodel\sql_expression_select_gen.py:132:5
|
130 | @overload
131 | def select(
132 | entity_0: _TScalar_0,
| -------- Prior parameter here was positional-or-keyword
133 | __ent1: _TCCA[_T1],
| ^^^^^^ Parameter name begins with__but will not be treated as positional-only
134 | ) -> Select[tuple[_TScalar_0, _T1]]: ...
|
info: A parameter can only be positional-only if it precedes all positional-or-keyword parameters
info: ruleinvalid-legacy-positional-parameteris enabled by default
So basically we can't have __var if there is a scalar parameter in front of this one.
As a quick fix, I changed all double underscores to singles, but it feels a bit like a hack. We could also suppress the ty warning, but that also feels wrong...
There was a problem hiding this comment.
I think just renaming it to single-underscored would be incorrect.
As I understand, double-underscored parameter names was a convention for position-only parameters before , / syntax was added in 3.8.
I suggest we update this to use names without leading underscores, and update template to add , / to each signature of select:
@overload
-def select(__ent0: _TCCA[_T0]) -> SelectOfScalar[_T0]: ...
+def select(__ent0: _TCCA[_T0], /) -> SelectOfScalar[_T0]: ...
@overload
-def select(__ent0: _TScalar_0) -> SelectOfScalar[_TScalar_0]: ...
+def select(__ent0: _TScalar_0, /) -> SelectOfScalar[_TScalar_0]: ...
# Generated overloads start
{% for signature in signatures %}
@overload
def select(
- {% for arg in signature[0] %}{{ arg.name }}: {{ arg.annotation }}, {% endfor %}
+ {% for arg in signature[0] %}{{ arg.name }}: {{ arg.annotation }}, {% endfor %} /,
) -> Select[tuple[{%for ret in signature[1] %}{{ ret }} {% if not loop.last %}, {% endif %}{% endfor %}]]: ...
{% endfor %}
# Generated overloads endAlternatively we can leave __ent and rename entity_.. parameters to __entity_..
| def __setattr__(cls, name: str, value: Any) -> None: | ||
| def __setattr__(cls, key: str, value: Any) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__setattr__(cls, name, value) | ||
| DeclarativeMeta.__setattr__(cls, key, value) | ||
| else: | ||
| super().__setattr__(name, value) | ||
| super().__setattr__(key, value) | ||
|
|
||
| def __delattr__(cls, name: str) -> None: | ||
| def __delattr__(cls, key: str) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__delattr__(cls, name) | ||
| DeclarativeMeta.__delattr__(cls, key) | ||
| else: | ||
| super().__delattr__(name) | ||
| super().__delattr__(key) |
There was a problem hiding this comment.
ty said the original code violates the Liskov Substitution Principle.
There was a problem hiding this comment.
ty is right about Liskov Substitution Principle violation, but I don't think we need to fix it this way.
object declares these methods with name parameter. So, using key here will not be correct.
This is actually minor issue as this is unlikely that these methods will be called with parameters passed by name.
So, I would revert changes and just ignore ty warning
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # pyproject.toml # uv.lock
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # pyproject.toml # uv.lock
YuriiMotov
left a comment
There was a problem hiding this comment.
Added a few suggestions in the comments. Please, take a look)
| def __setattr__(cls, name: str, value: Any) -> None: | ||
| def __setattr__(cls, key: str, value: Any) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__setattr__(cls, name, value) | ||
| DeclarativeMeta.__setattr__(cls, key, value) | ||
| else: | ||
| super().__setattr__(name, value) | ||
| super().__setattr__(key, value) | ||
|
|
||
| def __delattr__(cls, name: str) -> None: | ||
| def __delattr__(cls, key: str) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__delattr__(cls, name) | ||
| DeclarativeMeta.__delattr__(cls, key) | ||
| else: | ||
| super().__delattr__(name) | ||
| super().__delattr__(key) |
There was a problem hiding this comment.
ty is right about Liskov Substitution Principle violation, but I don't think we need to fix it this way.
object declares these methods with name parameter. So, using key here will not be correct.
This is actually minor issue as this is unlikely that these methods will be called with parameters passed by name.
So, I would revert changes and just ignore ty warning
| its `WHERE` clause, joined to the existing clause via `AND`, if any. | ||
| """ | ||
| return super().where(*whereclause) # type: ignore[arg-type] | ||
| return super().where(*whereclause) |
There was a problem hiding this comment.
It's ty's mistake that it doesn't notice type mismatch here. But I checked - passing bool argument works in runtime
| t_type = f"_T{i}" | ||
| t_var = f"_TCCA[{t_type}]" | ||
| arg = Arg(name=f"__ent{i}", annotation=t_var) | ||
| arg = Arg(name=f"_ent{i}", annotation=t_var) |
There was a problem hiding this comment.
I think just renaming it to single-underscored would be incorrect.
As I understand, double-underscored parameter names was a convention for position-only parameters before , / syntax was added in 3.8.
I suggest we update this to use names without leading underscores, and update template to add , / to each signature of select:
@overload
-def select(__ent0: _TCCA[_T0]) -> SelectOfScalar[_T0]: ...
+def select(__ent0: _TCCA[_T0], /) -> SelectOfScalar[_T0]: ...
@overload
-def select(__ent0: _TScalar_0) -> SelectOfScalar[_TScalar_0]: ...
+def select(__ent0: _TScalar_0, /) -> SelectOfScalar[_TScalar_0]: ...
# Generated overloads start
{% for signature in signatures %}
@overload
def select(
- {% for arg in signature[0] %}{{ arg.name }}: {{ arg.annotation }}, {% endfor %}
+ {% for arg in signature[0] %}{{ arg.name }}: {{ arg.annotation }}, {% endfor %} /,
) -> Select[tuple[{%for ret in signature[1] %}{{ ret }} {% if not loop.last %}, {% endif %}{% endfor %}]]: ...
{% endfor %}
# Generated overloads endAlternatively we can leave __ent and rename entity_.. parameters to __entity_..
|
|
||
|
|
||
| class_registry = weakref.WeakValueDictionary() # type: ignore | ||
| class_registry = weakref.WeakValueDictionary() |
There was a problem hiding this comment.
Do we even need this class_registry?
It's not used and after removing it all tests pass
mypywithtyin precommit,lint.sh& pyproject.toml.tyhappyI originally set out to have
mypyandtyrun together in precommit, but forsqlmodelI would argue that perhaps we want to removemypyalltogether already now, as it allows us to remove a lot oftype: ignorestatements thattythinks are unnecessary anyway.