Allow int Subclasses in Query#492
Allow int Subclasses in Query#492Exahilosys wants to merge 7 commits intoaio-libs:masterfrom Exahilosys:patch-1
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.
|
| 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.
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
intsubclasses that should definitely work.What do these changes do?
This new check allows all
intsubclasses 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
CHANGESfolder<issue_id>.<type>(e.g.588.bugfix)issue_idchange 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.