Coder Social home page Coder Social logo

regression due to #11055 about sqlalchemy HOT 10 CLOSED

zzzeek avatar zzzeek commented on May 27, 2024
regression due to #11055

from sqlalchemy.

Comments (10)

zzzeek avatar zzzeek commented on May 27, 2024

@francipvb any chance you can take a look at this and suggest corrections?

cc @CaselIT @agronholm

from sqlalchemy.

CaselIT avatar CaselIT commented on May 27, 2024

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.

CaselIT avatar CaselIT commented on May 27, 2024

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.

zzzeek avatar zzzeek commented on May 27, 2024

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.

CaselIT avatar CaselIT commented on May 27, 2024

I'm not sure. Maybe we can use some overloads?

Would it make sense to report this to mypy.

from sqlalchemy.

francipvb avatar francipvb commented on May 27, 2024

Hello,

I'm looking into this. It seems that mypy is more strict with this usecase.

from sqlalchemy.

zzzeek avatar zzzeek commented on May 27, 2024

can we get the PR for this?

from sqlalchemy.

sqla-tester avatar sqla-tester commented on May 27, 2024

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.

sqla-tester avatar sqla-tester commented on May 27, 2024

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.

sqla-tester avatar sqla-tester commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.