Closed junkmd closed 1 year ago
While reading specification.rst, I had a question that crossed my mind.
specification.rst
In below case, unless from __future__ import annotations is used, a NameError is raised at runtime.
from __future__ import annotations
NameError
https://github.com/CarliJoy/intersection_examples/blob/bcca49112164a9a8b0cdfb94569bb379c734b722/specification.rst?plain=1#L89-L98
To avoid runtime errors, it's necessary to use string literals for typing as shown below.
class LoginRequiredMixin: def dispatch(self: "LoginRequiredMixin & View", request, *args, **kwargs): ...
For expressing that self is a mixin, in order to convey the same meaning without using string literals, I think that it should be typed with using Self.
self
Self
class LoginRequiredMixin: def dispatch(self: Self & View, request, *args, **kwargs): ...
Moreover, it's necessary to consider the interaction with methods and attributes that return Self.
class Mixin: me: Self a: Mixin & T … b = a.me
In the above case, I think that b should be interpreted as Mixin & T by type checkers.
b
Mixin & T
Any opinions would be appreciated.
Feel free to create an MR
@CarliJoy
Hello!
I see, I will start working for the first pull request in this repo.
While reading
specification.rst
, I had a question that crossed my mind.In below case, unless
from __future__ import annotations
is used, aNameError
is raised at runtime.https://github.com/CarliJoy/intersection_examples/blob/bcca49112164a9a8b0cdfb94569bb379c734b722/specification.rst?plain=1#L89-L98
To avoid runtime errors, it's necessary to use string literals for typing as shown below.
For expressing that
self
is a mixin, in order to convey the same meaning without using string literals, I think that it should be typed with usingSelf
.Moreover, it's necessary to consider the interaction with methods and attributes that return
Self
.In the above case, I think that
b
should be interpreted asMixin & T
by type checkers.Any opinions would be appreciated.