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

Improve type definition of Mocker.__call__ #244

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Dec 29, 2023

Footnotes

  1. ParamSpec and Concatenate can't be used to add the m parameter (for two reasons: there's no way to concatenate to kwargs, and even if kw is not set on the Mocker instance, concatenating a posarg is only possible if it is added first (i.e. Concatenate[P, Mocker] is not possible))

@Viicos Viicos mentioned this pull request Jan 21, 2024
@jamielennox
Copy link
Owner

Responding to comment. I looked this over, there's a few bits I just need to figure out:

  • how much of the changes are real, and how much is black being black? Like replacing Optional[] with | None, is that an actual change that I need to research? (In general I don't care about black, but if it matters I'd do it as a separate pr so we can say there are no actual changes here).

  • I was going to look through which version introduced some of the syntax. I guess going forward I'm looking to support only the supported options like everyone else, but I just wanted to say least check it.

  • Given the drop of python 2, the need to maintain the types in the their own .pyi files has largely gone away. There's no real ROI I'm aware of that makes it an urgent process, but I was going to check how it looked after Remove py2 #248..

Anyway, that's my very late night rambling to do list, but it's probably fine. Still if there's a real functional change in their that you're waiting on I'd just submit that as something contained and reviewable on its own. That's a lot easier to review than something that rewrites a lot of syntax for no obvious benefit.

@Viicos
Copy link
Contributor Author

Viicos commented Jan 21, 2024

Yes sorry would have probably been easier in separate commits.

how much of the changes are real, and how much is black being black?

The only functional change can be looked up here.

Still if there's a real functional change in their that you're waiting on I'd just submit that as something contained and reviewable on its own. That's a lot easier to review than something that rewrites a lot of syntax for no obvious benefit.

Do you want me to make a separate PR for it?

I was going to look through which version introduced some of the syntax. I guess going forward I'm looking to support only the supported options like everyone else, but I just wanted to say least check it.

When writing stub files, you can usually make use of new typing features (in this case, the new union style syntax and builtins supporting subscripting: typing.List[int] -> list[int]) as soon as they are supported by the major type checkers, not when the Python version introducing this features is the last one being supported.

Given the drop of python 2, the need to maintain the types in the their own .pyi files has largely gone away.

It could be merged back into the source files indeed. However, the library seems to be doing a lot of magic, so it might be tricky in some places (whereas type stubs can express anything, even if it's not written the same way in the source). I'll investigate on that, and could make a PR with the types merged back if you are open to it (as it might take some review effort)

@jamielennox
Copy link
Owner

Yea, please extract the functional bit, that looks pretty trivial and i can just merge it straight away.

For the rest, sure, but it'll just kind of be on the todo list as i don't see a user impact that has any urgency.

@Viicos Viicos force-pushed the type-stubs-improvements branch from b74886d to 51d0a73 Compare January 22, 2024 14:44
@Viicos Viicos changed the title Improvements to type stubs Improve type definition of Mocker.__call__ Jan 22, 2024
@jamielennox
Copy link
Owner

I've merged all the python2 removal code. If you rebase it now the tests should work.

@Viicos Viicos force-pushed the type-stubs-improvements branch from 51d0a73 to 8f5dac3 Compare January 22, 2024 15:41
@jamielennox jamielennox merged commit 88c4ea7 into jamielennox:master Jan 22, 2024
6 checks passed
@Viicos Viicos deleted the type-stubs-improvements branch January 22, 2024 15:57
renovate bot referenced this pull request in allenporter/pyrainbird Mar 28, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [requests-mock](https://requests-mock.readthedocs.io/)
([source](https://togithub.com/jamielennox/requests-mock)) | `==1.11.0`
-> `==1.12.0` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/requests-mock/1.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/requests-mock/1.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/requests-mock/1.11.0/1.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/requests-mock/1.11.0/1.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>jamielennox/requests-mock (requests-mock)</summary>

###
[`v1.12.0`](https://togithub.com/jamielennox/requests-mock/releases/tag/1.12.0)

[Compare
Source](https://togithub.com/jamielennox/requests-mock/compare/1.11.0...1.12.0)

#### What's Changed

- Update copyright year by
[@&#8203;KrishanBhasin](https://togithub.com/KrishanBhasin) in
[https://github.com/jamielennox/requests-mock/pull/239](https://togithub.com/jamielennox/requests-mock/pull/239)
- Remove py2 by [@&#8203;jamielennox](https://togithub.com/jamielennox)
in
[https://github.com/jamielennox/requests-mock/pull/248](https://togithub.com/jamielennox/requests-mock/pull/248)
- Allow `raw` parameter to accept callable like body elements by
[@&#8203;jamielennox](https://togithub.com/jamielennox) in
[https://github.com/jamielennox/requests-mock/pull/249](https://togithub.com/jamielennox/requests-mock/pull/249)
- Improve type definition of `Mocker.__call__` by
[@&#8203;Viicos](https://togithub.com/Viicos) in
[https://github.com/jamielennox/requests-mock/pull/244](https://togithub.com/jamielennox/requests-mock/pull/244)
- Drop PBR Support by
[@&#8203;jamielennox](https://togithub.com/jamielennox) in
[https://github.com/jamielennox/requests-mock/pull/250](https://togithub.com/jamielennox/requests-mock/pull/250)
- fix(mocker.pyi): fix Mocker class type hints by
[@&#8203;pavellos21](https://togithub.com/pavellos21) in
[https://github.com/jamielennox/requests-mock/pull/251](https://togithub.com/jamielennox/requests-mock/pull/251)
- Remove unused `six` dependency by
[@&#8203;Viicos](https://togithub.com/Viicos) in
[https://github.com/jamielennox/requests-mock/pull/252](https://togithub.com/jamielennox/requests-mock/pull/252)

#### New Contributors

- [@&#8203;KrishanBhasin](https://togithub.com/KrishanBhasin) made their
first contribution in
[https://github.com/jamielennox/requests-mock/pull/239](https://togithub.com/jamielennox/requests-mock/pull/239)
- [@&#8203;Viicos](https://togithub.com/Viicos) made their first
contribution in
[https://github.com/jamielennox/requests-mock/pull/244](https://togithub.com/jamielennox/requests-mock/pull/244)
- [@&#8203;pavellos21](https://togithub.com/pavellos21) made their first
contribution in
[https://github.com/jamielennox/requests-mock/pull/251](https://togithub.com/jamielennox/requests-mock/pull/251)

**Full Changelog**:
jamielennox/requests-mock@1.11.0...1.12.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/allenporter/pyrainbird).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants