Typehint most of main.py, with consequent fixes elsewhere#1300
Merged
Conversation
25fba82 to
248da22
Compare
248da22 to
7f66c01
Compare
3eaafb7 to
0e37fb3
Compare
0e37fb3 to
5eb91dd
Compare
amjith
reviewed
Aug 3, 2025
| 'write_once', | ||
| 'write_pipe_once', | ||
| 'write_tee', | ||
| ] |
Member
There was a problem hiding this comment.
Non-blocking question. Do you think we need to hoist all these functions to the top level?
BTW, I'm fine with removing the @export decorator.
Contributor
Author
There was a problem hiding this comment.
I don't think we do need to hoist. It could be nicer not to.
amjith
approved these changes
Aug 3, 2025
5eb91dd to
644d682
Compare
* typehint >80% of main.py * requiring additional hints and fixes in config.py, sqlexecute.py, packages/parseutils.py, and others * typehint unhinted portions of sqlexecute.py * remove @export decorator and import explicitly into "special" * recast some uninformative variable names * assert that a connection is available before using it * take more care with: ssl config, port, and ssh_port types/defaults before creating a connection * local_infile is a boolean, not a string * ensure get_password_from_file() returns a value * assert that a PromptSession is available before invoking methods on it * set a fallback col/row size in case a prompt session is not available * declare and type self.conn in SQLExecute much earlier * take more care to distinguish falsey values from Nones in SQLExecute connect() * improve defaults passed to pymysql.connect(), matching them to the pymysql docs * test that self.conn is not None rather than checking for a "conn" attribute, before invoking close() * remove Python 2.x-compat Unicode literals trick for click * better catch empty database names in change_db() * take more care for edge-case values of text in one_iteration() * don't return None for connection_id_to_kill * clarify overlapping "e" variables * don't use self.sqlexecute when sqlexecute is already available * is_dropping_database() takes a string, not a list * typehint unhinted function in packages/parseutils.py * use only chain() for format_output() output * test isinstance(…, Cursor) rather than hasattr(…, "description") * set start = time() before try block * don't "return output_res(…)" when no return value is expected * update changelog
644d682 to
0261c9b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
main.pyconfig.pyandsqlexecute.py,packages/parseutils.py, and otherssqlexecute.py@exportdecorator and import explicitly intospeciallocal_infileis a boolean, not a stringget_password_from_file()returns a valuePromptSessionis available before invoking methods on itself.conninSQLExecutemuch earlierNones inSQLExecuteconnect()pymysql.connect(), matching them to the pymysql docsself.connis notNonerather than checking for aconnattribute, before invokingclose()change_db()textinone_iteration()Noneforconnection_id_to_killevariablesself.sqlexecutewhensqlexecuteis already availableis_dropping_database()takes a string, not a listpackages/parseutils.pychain()forformat_output()outputisinstance(…, Cursor) rather thanhasattr(…, "description")start = time()beforetryblockreturn output_res(…)when no return value is expected@amjith I tried to keep the cute
@exportdecorator but it is too dynamic for a static checker to understand.Checklist
changelog.md.AUTHORSfile (or it's already there).uv ruff check && uv ruff formatto lint and format the code.