-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Complete stubs for SQLAlchemy #1094
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
Conversation
Work towards fixing python#974
Went over the diff between current typeshed and my regenerated stubs.
This appears to be internal to sqlalchemy and just for testing.
This was just codemod.
Not sure why, but I started getting this error in a single file in sqlalchemy, although we have numerous violations across typeshed.
|
I can’t no longer import some of the top-level modules such as |
|
Re: |
|
|
||
| func = ... # type: _FunctionGenerator | ||
| modifier = ... # type: _FunctionGenerator | ||
| class GenericFunction(object): |
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.
Super should be Function not object. The auto-generated chain is probably lost around here:
class GenericFunction(util.with_metaclass(_GenericMeta, Function)):
...Otherwise we get type incompatibility errors for things like:
x: sa.ColumnElement
y: sa.ColumnElement
x = sa.sum(y)Where we try to assign sum type to sa.ColumnElement.
| @property | ||
| def primary_key(self) -> Any: ... | ||
| def primary_key(self): ... | ||
| def foreign_keys(self): ... |
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.
Should be @property, sqlalchemy is using @_memoized_property
| def description(self): ... | ||
| def _reset_exported(self): ... | ||
| @property | ||
| def columns(self): ... |
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.
Should stay as @property, sqlalchemy is using @_memoized_property, otherwise we can't access X.columns[name] for "function not being indexable".
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.
Thanks for checking these! I'm going to grep for _memoized_property throughout the codebase to find any others where I messed this up.
Grepped for with_metaclass in SQLAlchemy source code. There are already a number of usages of metaclass= in the Python 2 parts of typeshed, so I assume that it's OK.
From grepping for memoized_property in sqlalchemy.
|
Hm, I ran this against our codebase and there are some new errors:
|
|
Thanks for checking! I can fix those specific issues, but I'm beginning to think that maybe this PR's approach of mass-creating stubs for all of SQLAlchemy isn't the right one. |
|
Well what's currently in typeshed is also failing for us (just on different APIs). I'm beginning to think that maybe we should indeed delete the sqlalchemy stubs entirely (as was one option discussed in #974), at least for the time being. The |
|
I think that selectively ignoring whole modules or symbols would be better solution than to drop it completely. It already contains quite useful pieces of information about the library and can serve as a good starting point for further development. |
|
But there's no way to make mypy do that without each app copying a huge section to its mypy.ini file. |
|
When we consider dropping sqlalchemy from master typeshed, what do you think about being able to specify Where the The Larger libraries can be then maintained as separate git repositories. |
|
How about we allow the existing flag to have multiple args. Agreed we need to support adding extra typeshed dirs. You could also add it to $MYPYPATH. |
See discussion in #1094. If we do this we should make it easier in mypy to install 3rd party stubs that are used by default.
|
I'd like feedback from @matthiaskramm (pytype) and @vlasovskikh (PyCharm) -- what would your preferences be? |
|
No strong opinions on anything in That said, sqlalchemy has been making trouble for quite some time: |
|
I'm not sure if you were still looking for testing/input since it looks like the plan might be to just delete them now, but I'm still seeing quite a few similar errors with these new stubs (though I think it's less than with the currently included ones - I can confirm that if you'd like). Most of the errors seem to be similar to before though, incompatible types for assignments/return values/arguments where mypy considers a Column incompatible with the base type underlying it. My small example in #974 still demonstrates this issue with setting a One other error I got with these stubs was: from a line of code similar to: This argument should be valid though: http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.MetaData |
|
OK, sounds like we're leaning towards removing the stubs. If so, I'll close this PR and put the code in a separate repo, so that people who want to use it can include it manually. @Stiivi @gvanrossum I don't think we need to change mypy, since you can just write @Deimos Thanks for checking! I'm pretty sure no stubs will allow that code sample to work; the metaclass is too magical. Did it ever work for you? I'm getting |
|
Also, responding to the problems Guido found in his codebase:
On the latest version of SQLAlchemy,
These are using a decorator that magically inserts an extra argument. I'll grep for it in SQLAlchemy source and remove the arguments in the stubs.
This is set in an |
|
OK. Let's move the sqlalchemy to a separate project; whoever wants to own it can, AFAIK. PyCharm can include its own copy of it in their distribution. Can you merge my PR for that? |
|
Will do. |
See discussion in #1094. If we do this we should make it easier in mypy to install 3rd party stubs that are used by default.
|
PyCharm currently bundles Typshed, but we use only a few stubs from it at
the moment. We could bundle sqlachemy stubs from any other location as well.
вт, 28 марта 2017 г. в 17:23, Jelle Zijlstra <notifications@github.com>:
Will do.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1094 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHvq29zvf0I-k75AG0U-8HUghkOnbAjks5rqSYMgaJpZM4Mo8eb>
.
--
Andrey Vlasovskikh
Web: http://pirx.ru/
|
|
I just created https://github.com/JelleZijlstra/sqlalchemy-stubs. Interested people can add this repo to their MYPYPATH directly. @Stiivi if you like, I can add you as a collaborator to my repo. I'll also accept pull requests. |
|
@JelleZijlstra thank you, would be more than happy. |
Fixes #974 (hopefully!).
This is intended to fix false positive errors that arise from incomplete stubs.
This is a massive PR that will be hard to review. I did the following (all in separate commits):
To review this diff, I recommend you look only at the commits after the first one.
@Deimos @lincolnq @Stiivi would you mind testing the stubs from this PR against your codebase to see if you still get false positive errors from mypy?