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

Issue #33: convert to package and include typeshed type hints #34

Merged
merged 7 commits into from
Jun 26, 2021

Conversation

ncoghlan
Copy link
Collaborator

No description provided.

@ncoghlan ncoghlan requested a review from graingert June 26, 2021 10:43
@codecov
Copy link

codecov bot commented Jun 26, 2021

Codecov Report

Merging #34 (4b353b9) into master (77e9383) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #34   +/-   ##
=======================================
  Coverage   95.34%   95.34%           
=======================================
  Files           1        1           
  Lines         365      365           
  Branches       29       29           
=======================================
  Hits          348      348           
  Misses         14       14           
  Partials        3        3           
Impacted Files Coverage Δ
contextlib2/__init__.py 95.34% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77e9383...4b353b9. Read the comment docs.

# type ignore to deal with incomplete ParamSpec support in mypy
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore

if sys.version_info >= (3, 7):
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this always defined in contextlib2?

Copy link
Member

@graingert graingert Jun 26, 2021

Choose a reason for hiding this comment

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

You could swap out all the if sys.version_info >= ...: for if True: to minimize the diff noise?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, true. And I like that suggestion for minimising the diff.

Copy link
Member

Choose a reason for hiding this comment

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

The ABC will be a bit troublesome as you might need to import them from typing_extensions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't sure about that, as the typing module imports were unconditional in the typeshed version as well - it only guarded their aliasing to contextlib API entries.

I figured either mypy (et al) must be doing some shenanigans behind the scenes to let that work even on older Python versions, or else it needed to be fixed in typeshed first, and then contextlib2 could inherit that fix.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Heh, we both found the same info in about the same time, but picked different subthreads to update first :)

Copy link
Member

@graingert graingert left a comment

Choose a reason for hiding this comment

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

Awesome, I'm very excited to use this!

You might want add type annotations for the deprecated classes and methods?

@ncoghlan
Copy link
Collaborator Author

There are only two deprecated APIs, and I honestly suspect I should just remove them completely at this point: #31 (not in 21.6.0, though).

I did enhance the CI to actually run mypy, though, and confirmed locally that it failed as expected if there was something wrong in the pyi file.

So I'll merge this now, check everything over again in the morning, and assuming I don't think of anything else I missed, I'll cut the release tomorrow

(And in writing that, I realised I need release notes for this change!)

@ncoghlan ncoghlan merged commit bed62be into jazzband:master Jun 26, 2021
@ncoghlan
Copy link
Collaborator Author

@graingert Ah, that would explain why mypy only complained when I introduced outright errors into the stub, and not when I only made it inconsistent with the actual implementation.

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