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

refactor: slightly improve typing for cqlengine #197

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

VincentRPS
Copy link

This PR slightly improves typing for the CQLEngine.
I am having a bit of trouble though, because of the weird way Model and Queries are done,
its very hard to properly type model.object.* functions properly. Any ideas?

@VincentRPS
Copy link
Author

seems like there's no way to properly type model.object.* functions so, as for what I see, this PR should be ready

@@ -835,9 +838,13 @@ def _class_get_connection(cls):
def _inst_get_connection(self):
return self._connection or self.__connection__

def __getitem__(self, s: slice | int) -> M | list[M]:
Copy link

Choose a reason for hiding this comment

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

this is a bit more then adding types, this add new functionality.
I think it should come on it's own commit, with the reasoning why it's needed

Copy link
Author

Choose a reason for hiding this comment

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

ah yeah, the reason this was added was mostly since I found proper typing for a model on ModelQuerySet to be nearly impossible

@fruch
Copy link

fruch commented Dec 27, 2022

@VincentRPS I've let CI run on this change, but I think it might fail on python2

for reasons™️ we still need to support python2, so this might need to wait a bit, for when we can drop python2 support completely

@fruch
Copy link

fruch commented Dec 29, 2022

@VincentRPS

seems like it's failing with python3.7

2022-12-27T19:04:08.5435241Z ______________ ERROR collecting tests/unit/cqlengine/test_udt.py _______________
2022-12-27T19:04:08.5435657Z /project/tests/unit/cqlengine/test_udt.py:18: in <module>
2022-12-27T19:04:08.5436038Z     from cassandra.cqlengine.models import Model
2022-12-27T19:04:08.5436576Z /tmp/tmp.ALd4n4nucG/venv/lib/python3.7/site-packages/cassandra/cqlengine/models.py:24: in <module>
2022-12-27T19:04:08.5437001Z     from cassandra.cqlengine import query
2022-12-27T19:04:08.5437514Z /tmp/tmp.ALd4n4nucG/venv/lib/python3.7/site-packages/cassandra/cqlengine/query.py:1073: in <module>
2022-12-27T19:04:08.5437975Z     T = TypeVar('T', 'ModelQuerySet')
2022-12-27T19:04:08.5438399Z /opt/python/cp37-cp37m/lib/python3.7/typing.py:545: in __init__
2022-12-27T19:04:08.5438786Z     raise TypeError("A single constraint is not allowed")
2022-12-27T19:04:08.5439150Z E   TypeError: A single constraint is not allowed

@fruch
Copy link

fruch commented Dec 29, 2022

@VincentRPS

and as expected python2 doesn't support type annotations:

______________ ERROR collecting tests/unit/cqlengine/test_udt.py _______________
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/_pytest/python.py:507: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/py/_path/local.py:704: in pyimport
    __import__(modname)
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/_pytest/assertion/rewrite.py:304: in load_module
    exec(co, mod.__dict__)
tests/unit/cqlengine/test_udt.py:18: in <module>
    from cassandra.cqlengine.models import Model
E     File "/home/runner/work/python-driver/python-driver/cassandra/cqlengine/models.py", line 90
E       def __get__(self, obj: Any, model: "BaseModel"):
E                            ^
E   SyntaxError: invalid syntax
=============================== warnings summary ===============================

@fruch fruch added the enhancement New feature or request label Jan 9, 2023
@VincentRPS
Copy link
Author

@VincentRPS

and as expected python2 doesn't support type annotations:

______________ ERROR collecting tests/unit/cqlengine/test_udt.py _______________
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/_pytest/python.py:507: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/py/_path/local.py:704: in pyimport
    __import__(modname)
/opt/hostedtoolcache/Python/2.7.18/x64/lib/python2.7/site-packages/_pytest/assertion/rewrite.py:304: in load_module
    exec(co, mod.__dict__)
tests/unit/cqlengine/test_udt.py:18: in <module>
    from cassandra.cqlengine.models import Model
E     File "/home/runner/work/python-driver/python-driver/cassandra/cqlengine/models.py", line 90
E       def __get__(self, obj: Any, model: "BaseModel"):
E                            ^
E   SyntaxError: invalid syntax
=============================== warnings summary ===============================

hmm, seeing that I'd have to say it'd be better waiting until py2 support is dropped

@fruch
Copy link

fruch commented Jan 11, 2023

thanks @VincentRPS, I'll mark this one as pending for now

@fruch fruch added the pending label Jan 11, 2023
@fruch fruch removed the pending label Jul 18, 2023
@fruch
Copy link

fruch commented Jul 18, 2023

@VincentRPS, now that we remove python2 support, we can try this again

@fruch
Copy link

fruch commented Jul 18, 2023

@VincentRPS, I would recommend send it also to the upstream cassandra (don't know when they would except it)

@fruch
Copy link

fruch commented Jul 18, 2023

Seems like those changes are also breaking python3.7, so for now we can't merge those

@fruch fruch added the pending label Jul 18, 2023
@VincentRPS
Copy link
Author

@fruch I thought I had already replied here but I guess I didn't, it should work with 3.7 now since I did a little fix, though I could be mistaken.

@fruch
Copy link

fruch commented Aug 1, 2023

@fruch I thought I had already replied here but I guess I didn't, it should work with 3.7 now since I did a little fix, though I could be mistaken.

I'll let CI run again

@fruch
Copy link

fruch commented May 30, 2024

@fruch I thought I had already replied here but I guess I didn't, it should work with 3.7 now since I did a little fix, though I could be mistaken.

I'll let CI run again

I've rebase this one, and triggered CI again

@Lorak-mmk Lorak-mmk self-assigned this Jun 1, 2024
@Lorak-mmk Lorak-mmk self-requested a review June 1, 2024 09:27
@Lorak-mmk
Copy link

@VincentRPS could you send this to upstream? It would be better to do it there: less conflicts when merging + we don't really touch cqlengine code, so it's hard to do a proper review.

@Lorak-mmk Lorak-mmk removed their assignment Jul 31, 2024
@Lorak-mmk Lorak-mmk removed their request for review September 20, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants