Comments (10)
@francipvb any chance you can take a look at this and suggest corrections?
from sqlalchemy.
mypy is saying:
This is likely because "reflect of MetaData" has named arguments: "bind". Consider marking them positional-only
If I apply this change
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 8436aac43..780576e32 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -5691,6 +5691,7 @@ class MetaData(HasSchemaAttr):
def reflect(
self,
bind: Union[Engine, Connection],
+ /,
schema: Optional[str] = None,
views: bool = False,
only: Union[
then everything passes.
But we can't do that on 2.0 since 3.7 does not support them (IIRC)
from sqlalchemy.
This is also liked by mypy:
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 8436aac43..04774d190 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -5690,7 +5690,7 @@ class MetaData(HasSchemaAttr):
@util.preload_module("sqlalchemy.engine.reflection")
def reflect(
self,
- bind: Union[Engine, Connection],
+ __bind: Union[Engine, Connection],
schema: Optional[str] = None,
views: bool = False,
only: Union[
@@ -5786,7 +5786,7 @@ class MetaData(HasSchemaAttr):
"""
- with inspection.inspect(bind)._inspection_context() as insp:
+ with inspection.inspect(__bind)._inspection_context() as insp:
reflect_opts: Any = {
"autoload_with": insp,
"extend_existing": extend_existing,
@@ -5844,7 +5844,7 @@ class MetaData(HasSchemaAttr):
missing_str = ", ".join(missing)
raise exc.InvalidRequestError(
f"Could not reflect: requested table(s) not available "
- f"in {bind.engine!r}{s}: ({missing_str})"
+ f"in {__bind.engine!r}{s}: ({missing_str})"
)
load = [
name
Overall this seems more like a bug of mypy.
pylance and pyright report no errors
from sqlalchemy.
we can't change that name because people may send it by name.
can we change the paramspec and/or add alternate paramspecs that work with metadata.reflect as is ?
from sqlalchemy.
I'm not sure. Maybe we can use some overloads?
Would it make sense to report this to mypy.
from sqlalchemy.
Hello,
I'm looking into this. It seems that mypy is more strict with this usecase.
from sqlalchemy.
can we get the PR for this?
from sqlalchemy.
Francisco Del Roio has proposed a fix for this issue in the main branch:
Fix typing issue in MetaData.reflect()
in AsyncIO context https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5242
from sqlalchemy.
Francisco Del Roio has proposed a fix for this issue in the rel_2_0 branch:
Fix typing issue in MetaData.reflect()
in AsyncIO context https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5263
from sqlalchemy.
Francisco Del Roio has proposed a fix for this issue in the main branch:
Fix typing issue in MetaData.reflect()
with asyncio. https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5242
from sqlalchemy.
Related Issues (20)
- Parameter substitution fails when statement has a postgres style cast HOT 5
- reflecting oracle synonym of synonym over dblink HOT 4
- Changing decimal separator to comma using locale.setlocale causes crash on MSSQL columns of decimal type HOT 3
- Generated syntax error when using funcs in server_default in MySQL
- NoForeignKeysError and AmbiguousForeignKeysError after upgrade to 2.x HOT 5
- selectin_polymorphic does not work for multiple level joined inheritance HOT 2
- ColumnCollection.get(col, default) types as Optional even with default HOT 2
- bulk_save_objects() w/ return defaults writes incorrect identity key HOT 4
- `sqlalchemy.utils.langhelpers.TypingOnly` too rigidly prevents special dunders from appearing HOT 5
- func.count argument typing issue HOT 1
- Bundle labels are wrong for new style select only (query works ?!) HOT 9
- Use of `raise NotImplementedError` instead of `NotImplemented` HOT 1
- Design a Repository pattern with sqlalchemy HOT 1
- Add `name` to `with_polymorphic ` HOT 2
- _JoinedListener can sneak into a metadata collection if Enum adapts itself, which can happen now, prohibiting serialization HOT 2
- TypeAlias cannot be found in type_annotation_map HOT 2
- Typing: of_type method not properly generic. HOT 1
- Add `insert_default` param to `Column` HOT 2
- many to many loaded relation instances partially missing reverse relation
- Add additional information to the `ReflectedColumn`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlalchemy.