Skip to content
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

RM-49 Reduce field_to_sqlalchemy_type complexity #224

Conversation

ryantimjohn
Copy link
Contributor

No description provided.

@ryantimjohn ryantimjohn marked this pull request as ready for review March 8, 2023 21:20
@ryantimjohn ryantimjohn requested a review from Brunope March 8, 2023 21:21
@ryantimjohn
Copy link
Contributor Author

@Brunope , I pulled out the typecasting from the function map.

I think I do have a preference for keeping the one/two-liners as lambdas rather than having a ton ton of fully-scoped functions in the code. Seems like it'd get crowded.

'datetime': lambda field, driver: driver.type_for_date_plus_time(has_tz=False),
'datetimetz': lambda field, driver: driver.type_for_date_plus_time(has_tz=True),
'time': lambda field, driver: sqlalchemy.sql.sqltypes.TIME(timezone=False)
if driver.supports_time_type() else sqlalchemy.sql.sqltypes.VARCHAR(8),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these multi-line inline if statements are kinda weirdin me out, sure it doesn't need a backslash or somethnig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too but flake8 says this is where they go, I got a hanging indent error for trying to make them look reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think about just putting everything in parens

@Brunope
Copy link
Collaborator

Brunope commented Mar 8, 2023

Generally, all the casting is confusing to me, I know the code was already using it though. Why is it necessary? Is it because DBDriver and RecordsSchemaField don't use type hints so we have to cast their fields for them? To me, one of the big advantages of type-checking is a compile-time guarantee that you're passing all the right types to all the right functions (for us when we make typecheck). But type casting voids that guarantee cause you can type cast to whatever type want, so why even have the hint in the first place?

Anyway, just musing on the general state of this project, nothing for us to do about this right now

@ryantimjohn
Copy link
Contributor Author

Generally, all the casting is confusing to me, I know the code was already using it though. Why is it necessary? Is it because DBDriver and RecordsSchemaField don't use type hints so we have to cast their fields for them? To me, one of the big advantages of type-checking is a compile-time guarantee that you're passing all the right types to all the right functions (for us when we make typecheck). But type casting voids that guarantee cause you can type cast to whatever type want, so why even have the hint in the first place?

Anyway, just musing on the general state of this project, nothing for us to do about this right now

The reason we're using type hints here in particular is that lambdas don't allow type hinting and casting works as a workaround so that we pass mypy typechecking but, yes, you're right, casting != type hinting so we wouldn't get the compile time error that we're looking for. I guess it's a good reason to use fully scoped functions?

@ryantimjohn ryantimjohn added this pull request to the merge queue Mar 9, 2023
Merged via the queue into master with commit 11241ce Mar 9, 2023
@ryantimjohn ryantimjohn deleted the RM-49-records_mover-records-schema-field-sqlalchemy.py-127-1-C901-field_to_sqlalchemy_type-is-too-complex-16 branch April 18, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants