refactor: slightly improve typing for cqlengine
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?
seems like there's no way to properly type model.object.* functions so, as for what I see, this PR should be ready
@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
@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
@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 ===============================
@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
thanks @VincentRPS, I'll mark this one as pending for now
@VincentRPS, now that we remove python2 support, we can try this again
@VincentRPS, I would recommend send it also to the upstream cassandra (don't know when they would except it)
Seems like those changes are also breaking python3.7, so for now we can't merge those
@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 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 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
@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.