Open mikapfl opened 1 year ago
Is it not possible to use from __future__ import annotations
combined with if TYPE_CHECKING
to get around this?
Hm, maybe it is. I think I tried using quotes around types (the equivalent of from __future__ import annotations
), but I didn't try if TYPE_CHECKING
, so maybe the combination can do the trick.
I think the TYPE_CHECKING
guard should work.
I don't think `RunGroupBy is well-typed currently either.
RunGroupBy
could use a generic with a TypeVar
bound to a BaseScmRun
(I think I've used the poorly named T
variable). Then the type on run.groupby
would be RunGroupBy[Self]
and the apply functions would know which type they should return.
The generic TypeVar could work, but binding it to a BaseScmRun
would introduce dependency circles again, no? We could just not bind it at all, which I think would be fine, no one is instantiating RunGroupBy
s out of whole cloth anyway.
Added typehints in #262
Is your feature request related to a problem? Please describe.
I get the error:
if I use
run.groupby(…).apply(…)
. That's a bit sad.Describe the solution you'd like
It would be great to add type information to
RunGroupBy.apply()
, however that's not really possible because there would be a dependency cycle:run.groupby()
returns aRunGroupBy
object (and therefore has to importscmdata.groupby
), andRunGroupBy.apply()
return anScmRun
object (and therefore has to importscmdata.run
).I'm not sure how to properly solve this.
Describe alternatives you've considered
We could:
Protocol
ize ScmRun. Sounds painful and like a lot of work, but would decouple implementation and types clearly.Protocol
ize RunGroupBy. Probably less work, but I'm not sure ifrun.py
can live without importingscmdata.groupby
, so probably doesn't break the cycle?