-
Notifications
You must be signed in to change notification settings - Fork 41
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
stubs use implicit reexports #187
Comments
Hi, I'm not sure this is a bug actually. The elements that are not re-exported are not included in the the So I think we should decide if the public interface is |
My usecase is I want to use these type definitions when typing my own code. e.g. I have some function that accepts a def do_select(c: ColumnClause) -> Select:
return select(c).select_from("user") Unless all of these types are internal and not supposed to be used at all (in which case they should probably be renamed with a leading Right now my code passes mypy unless I install the stubs, then I get dozens of failures due to all of these names in my codes hints no longer existing. |
I probably explained myself poorly. The type is public in the |
Hmm, I see. I have been using the documented type names - so How would I even determine the correct non-reexported name to use in my own type hints other than tracing the imports thru the source code? Anyway, changing my sample code above it now passes mypy import sqlalchemy
CC = sqlalchemy.sql.elements.ColumnClause |
I tend to agree that probably anything that's in expression should be exported, since the module seems mostly a public interface one. @zzzeek thoughts? |
all of these words are supposed to be available from sqlalchemy.sql.expression, and sqlalchemy.sql.elements is an internal name. so importing from "sqlalchemy.sql.expression" should produce a name that does not produce mypy errors. |
Should all be updated in Sqlalchemy then? |
that was my immediate impression but with all things mypy there is some uncertainty |
I'll update both then. Is these some other module that may be in the same situation and should.be checked? |
I think any module that is in the docs should export the names it documents |
doesnt apply to the stubs here, but for SQLAlchemy itself which will be retiring the separate stubs package, there seems to be some debate over if a Python package w/ py.typed needs to do explicit re-exports: python/mypy#8754 |
The documentation does give examples that yield mypy errors, such as this one with |
note that the v2 documentation assumes that this package is not being used |
Describe the bug
mypy enables
--no-implicit-reexport
for stub files:https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport
Many of the sqlalchemy stubs reexport and so mypy seems to not recognize those exports.
Expected behavior
mypy should not fail
To Reproduce
cc.py
:Error
Versions.
Additional context
Manually editing
.../lib/python3.8/site-packages/sqlalchemy-stubs/sql/expression.pyi
and changing the import ofColumnClause
tofrom .elements import ColumnClause as ColumnClause
fixes this.There are other objects that are also implicitly re-exported and result in mypy errors -
sqlalchemy.sql.expression.Executable
,sqlalchemy.sql.expression.FunctionElement
,sqlalchemy.sql.expression.Tuple
etc.The text was updated successfully, but these errors were encountered: