-
-
Notifications
You must be signed in to change notification settings - Fork 800
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
Started typing codebase #1299
Started typing codebase #1299
Conversation
… of AsyncHttpConsumer
Now only the last two points need some clarification.
|
channels/auth.py
Outdated
@@ -20,7 +22,7 @@ | |||
|
|||
|
|||
@database_sync_to_async | |||
def get_user(scope): | |||
def get_user(scope: Dict[str, Any]) -> Awaitable[Union[User, AnonymousUser]]: |
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.
would it not make more sense to make the database_sync_to_async
be generic
def database_sync_to_async(method: Callable[SomeGenericVar...]) -> Callable[ Awaitable[TheGenericReturnOfTHeCallable]]
....
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.
It's not that easy, database_sync_to_async inherits from SyncToAsync class from asgiref library.
Are you suggesting that I should inherit the call method to then type it like you wrote?
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.
good point, no lets just leave that as is.
…ng and a bunch of work on the whole codebase
… support custom user
Catch up with master
We'll see, in the mean time I have to keep in mind compatibility with python 3.5. How should I deal with import sorting? Is there a tool for sorting them before a commit or a configuration in the editor to enable? |
Never mind I figured out how to use black and isort |
I'm waiting for someone to review the PR. @matthiask @carltongibson @hishnash anyone? Can you please give some feedback or just merge the PR? |
HI @WisdomPill. I'm currently working on an update for Daphne. Then I'll cut back to channels. I'll have a look at this then. |
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.
Hi @WisdomPill.
This looks good. Thank you for the effort.
Can I ask a question? Is there any shorthand for this:
Dict[str, Any]
Can we define an alias so we can just pass, say StrDict
— that's rubbish but you get the idea?
(Like 99% of Dicts are Dict[str, Any]
so it seems quite boilerplatey...)
@carltongibson done! |
Hi @WisdomPill. That was quick. 🙂 Still not sure about I'm looking at releases here for Sept, so will do something with this for then. Good work! |
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.
HI @WisdomPill.
Sorry for the slow follow-up here. This has been bugging me greatly, and I haven't had a chance to get to it. Anyhow...
Please create a types
or typing
module — What do Python folks do here? —
Then create proper type alias wherever you have something like Optional[Tuple[str, Tuple[str, Any], StrDict]]
. I simply don't want to look at that. 🙂 Instead I want to see RouteMatch
or such...
Then we'll hopefully get something meaningful. i.e. a scope
is an AsgiScope
(or just Scope
), which if I'm interested I'll go and see is a Dict[Str: Any]
— but only certain keys are allowed, so can we tighten that? (if we can't tighten it now, maybe we will over time. Maybe we'll get asgiref
to declare that type, and so on...)
Liberal use of type aliases is the key to success here. (As they do in Haskell and friends.)
Make sense?
Thanks!
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.
fix the merge error plz
@carltongibson is there anything left in order to merge the pull request? |
@WisdomPill Just me getting another chance to review it. 🙂 Thank you for your efforts here! |
Stumbled upon this issue because I was looking to see the status of type hinting in Django, so I'd love to see these changes pulled! |
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 should have fixed everything in the following commits, closing che changes request.
Sorry I just discovered this feature, I'm a noob in open source software
@carltongibson just a friendly reminder to review the changes and to point out that I alligned the changes with channels/master. |
Hi @WisdomPill. Thanks for your efforts here. I'm just waiting to see what happens with the discussion on Django before coming back here. |
Gonna close this for now. Further discussion on #1819. |
Fixes #893
First of all, I want to point out that this is a process and maybe it will not be completed in every piece of code right away with just one pull request.
I started adding typing only on functions to the project but I have some questions about some parts of the code.
The user is always a Union[User, AnonymousUser]?
Is the message in Consumers always a dictionary?
I have a problem with AsyncHttpConsumer that throws a strange exception
Is it mandatory to put the output if there's no return value?
The code in close method of web sockets can be a number or a bool, not anything else?
By the way this is my first pull request to the project, so if there's anything else I should do