-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
I have found myself having to do explicit type conversions of `int` subclasses that should definitely work. This new check allows all `int` subclasses through except `bool`, which should obviously be rejected.
Codecov Report
@@ Coverage Diff @@
## master #492 +/- ##
=======================================
Coverage 99.57% 99.57%
=======================================
Files 4 4
Lines 708 712 +4
Branches 157 158 +1
=======================================
+ Hits 705 709 +4
Misses 3 3
Continue to review full report at Codecov.
|
yarl/_url.py
Outdated
@@ -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 |
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.
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?
Would you describe your use case? |
@webknjaz I can add tests, please allow for some time as I'm currently on holiday. Also, instead of using the built-in @asvetlov I am making a package with a subclass of Since |
I have created both positive and negative tests by restructuring and expanding the current type-checking strategy to a more compact one. As an extra to the PR, I would also suggest allowing |
The most common |
Fixed by #505 |
@Exahilosys thanks for the initial PR! |
Fix dependencies. 1.6.0 (2020-09-23) ================== Features -------- - Allow for int and float subclasses in query, while still denying bool. `#492 <https://github.com/aio-libs/yarl/issues/492>`_ Bugfixes -------- - Do not requote arguments in ``URL.build()``, ``with_xxx()`` and in ``/`` operator. `#502 <https://github.com/aio-libs/yarl/issues/502>`_ - Keep IPv6 brackets in ``origin()``. `#504 <https://github.com/aio-libs/yarl/issues/504>`_
https://build.opensuse.org/request/show/838272 by user dirkmueller + dimstar_suse - update to 1.6.0: - Allow for int and float subclasses in query, while still denying bool. `#492 <https://github.com/aio-libs/yarl/issues/492>`_ - Do not requote arguments in ``URL.build()``, ``with_xxx()`` and in ``/`` operator. `#502 <https://github.com/aio-libs/yarl/issues/502>`_ - Keep IPv6 brackets in ``origin()``. `#504 <https://github.com/aio-libs/yarl/issues/504>`_
I have found myself having to do explicit type conversions of
int
subclasses that should definitely work.What do these changes do?
This new check allows all
int
subclasses through exceptbool
, which should obviously be rejected.Are there changes in behavior for the user?
Nope. I can't imagine backward compatibility being an issue.
Checklist
CHANGES
folder<issue_id>.<type>
(e.g.588.bugfix
)issue_id
change it to the pr id after creating the PR.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.Fix issue with non-ascii contents in doctest text files.