-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[engine] Fix some type hints when request
is passed
#9077
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9077 +/- ##
===========================================
+ Coverage 73.91% 73.93% +0.01%
===========================================
Files 428 429 +1
Lines 44530 44546 +16
Branches 3881 3881
===========================================
+ Hits 32916 32934 +18
+ Misses 11614 11612 -2
|
cvat/apps/engine/types.py
Outdated
from cvat.apps.iam.middleware import WithIAMContext | ||
|
||
|
||
class PatchedRequest(HttpRequest, Request, WithUUID, WithIAMContext): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think PatchedRequest
gives off the wrong idea. "Patched" implies some sort of change, but we only add new attributes. How about something like ExtendedRequest
or AugmentedRequest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just engine.types.Request
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just
engine.types.Request
?
IMO, it's too ambiguous. But if both you and @Marishka17 prefer it, I'm not going to object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it should be something like HttpRequest
or ApiRequest
, but we need to avoid confusion with other requests we already have, such as function requests or async operation requests. I'm not sure this module (called types
) is a good place for such an abstraction, maybe it should be something server API or http related (e.g. we already have view_uitls
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpRequest
would be ambiguous too (since it's the name of the base Django type).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of inclusion of Extended
in the name? Imagine a situation where there is a private app with some new middleware, which also adds some new fields. I don't think ExtendedExtendedAPIRequest
would be a good name for that updated request type. That's why I suggested using something problem-oriented, like HttpRequest
(which we already have in Django) or ApiRequest
. Extended
just doesn't add much, it's better to use a type with the same name as the base type, just defined in a properly named module. It's likely that we'll use it in most places in the code. If we want to switch type annotations to an updated HttpRequest
in all the APIs, we can do this by using from cvat.apps.some_speaking_module_name import HttpRequest
. In fact, this engine
's HttpRequest
could already be inherited from a IAM
's HttpRequest
with the necessary fields added, and which could be used in relevant type annotations in IAM, because it is the module contract and scope (IAM isn't supposed to depend on engine
and it uses engine
in just 1 place).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of inclusion of Extended in the name?
To give my two cents: it's to make the name more descriptive. It's like Request
, but, well... extended. It makes it clear to someone reading the codebase that it's not the original Request
type, but is compatible with it.
Admittedly, it doesn't say much about how the type was extended, but neither does ApiRequest
. 🤷
I don't think
ExtendedExtendedAPIRequest
would be a good name for that updated request type.
It could be EnterpriseExtendedRequest
.
@Marishka17 What name do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want a distinct name, it could also be CoreHttpRequest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What name do you prefer?
I'm no longer code owner to give my preferences :)
Initially I would have prefer to use ExtendedRequest
just because I know that original type was Request
from rest framework. But if it "intersects" with the names in our logic and it isn't clear what it extends, let's use what do you or Maxim say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm the one who suggested ExtendedRequest
, so I'm obviously fine with it. That's two of us against one, so I'm going to go ahead and merge this. It's an internal type, so we can always rename it if needed.
|
Motivation and context
Since we are adding custom attributes to the request object (such as
uuid
oriam_context
), using theRequest
type is no longer appropriate.Based on #9075
How has this been tested?
Checklist
develop
branch- [ ] I have created a changelog fragment- [ ] I have updated the documentation accordingly- [ ] I have added tests to cover my changes- [ ] I have linked related issues (see GitHub docs)License
Feel free to contact the maintainers if that's a concern.