Skip to content
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

Allow int Subclasses in Query #492

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def _query_seq_pairs(cls, quoter, pairs):
def _query_var(v):
if isinstance(v, str):
return v
if type(v) is int: # no subclasses like bool
if isinstance(v, int) and not isinstance(v, bool): # no subclasses like bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably make it slower so I'll leave it to @asvetlov to decide. But you'd probably have to add tests for this (both negative and positive) and find other places in code that use the same idiom.

Also, what if such int subclass implements a weird __str__() method that returns something odd? This would create hard-to-debug issues in the calling code, especially if your colleagues don't know YARL internals. Is it really worth it? This could probably be mitigated by an extra check for v.__str__ is int.__str__ but isn't it overkill?

return str(v)
raise TypeError(
"Invalid variable type: value "
Expand Down