GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CI,TYP: Bump mypy to 1.4.1 by BvB93 · Pull Request #23764 · numpy/numpy

Conversation

@BvB93

@BvB93 BvB93 commented May 15, 2023

Copy link
Copy Markdown
Member

This PR bumps the mypy version used throughout the test suite from 0.981 to 1.3.0 (it's been a while...).

In addition to mypy now having implemented support for typing.Concatenate there seems been some changes in how it deals with the joining of super- and sub-classes. The end result as that, e.g. the likes of np.float64 + np.float32 were previously interpretted as producing np.floating[_64Bit] while not it results in a np.floating[_64Bit | _32Bit] union.

While non-ideal, this upstream change is admitetly a minor inconvenience in the grand scheme of things, mostly because the typing of dtype bitsizes in numpy is severely lacking due to the sheer number of challenges associated with it.

Lastly, while not implemented in this PR there's also typing.Self support ever since mypy 1.0.0. This type is essentially a bit of syntactic sugar to make typing involving self and cls a bit easier, removing their need for hyper-specialized typevars. Something for a future PR perhaps.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BvB93 BvB93 added the 41 - Static typing label May 15, 2023
@BvB93 BvB93 added this to the 1.25.0 release milestone May 15, 2023
@BvB93

BvB93 commented May 15, 2023

Copy link
Copy Markdown
Member Author
>               pytest.fail(f"Unexpected mypy standard error\n\n{stderr}")
E               Failed: Unexpected mypy standard error
E               
E               mypy: "../../venv-for-wheel/lib/python3.9/site-packages/mypy_extensions.py" shadows library module "mypy_extensions"
E               note: A user-defined top-level module with name "mypy_extensions" is not supported

Some more debugging for tomorrow. The error messages differ a bit from platform to platform, though this seems to suggest that a mypy from outside venv-for-wheel/lib/python3.9/... is clashing with a mypy_extensions installation inside the venv environment. Thus far I've been unable to reproduce the issue locally though (be it either in mac or windows) with a simple python .\runtests.py -t numpy/typing --mode=full.

Any thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg

seberg commented May 17, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

A quick google search finds this: https://stackoverflow.com/questions/64806361/installing-mypy-leads-to-shadows-library-module-error
EDIT: Also this doc update to mypy python/mypy@4825e34

The travis-CI run sets the MYPYPATH to the python path, which is strongly discouraged (and I guess mypy broke it entirely?). Sounds like fixing MYPYPATH to just include numpy should do the trick?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg

seberg commented May 17, 2023

Copy link
Copy Markdown
Member

Hmmm, fun... there is another issue now about C and D drive in some runs, and the error didn't actual go away in others? So probably that was at least not the core of the issue, or any chance of a caching problem?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BvB93

BvB93 commented May 17, 2023

Copy link
Copy Markdown
Member Author

It did solve the Travis failure though; and the fact that all other runs that had previously failed do so again do make me suspect that there's more going on here than a simple caching problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg

seberg commented May 17, 2023

Copy link
Copy Markdown
Member

Hmmm, some of the failures seem to be about not installing typing_extensions? It still shows up in test_requirements.txt and the cirrus setup?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

seberg
seberg reviewed May 17, 2023
View reviewed changes
Comment thread test_requirements.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

@BvB93

BvB93 commented May 17, 2023

Copy link
Copy Markdown
Member Author

Hm, not sure about typing_extensions lacking. Pretty much all the errors mention either a C/D path mismatch or, more directly, that either the mypy_extensions or typing_extension in the testing venv is shadowing wherever the package was installed originally.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BvB93

BvB93 commented May 17, 2023

Copy link
Copy Markdown
Member Author

Think I may have found something here; seems the problem might be that it is directly run against something in site-packages: python/mypy#11477. It's annoying that this has now become an issue all of a sudden, though I wonder if we could run mypy directly against the numpy source? The .pyi files aren't affected by the build stage after all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label May 22, 2023
@charris charris removed this from the 1.25.0 release milestone May 22, 2023
@BvB93
BvB93 marked this pull request as draft June 6, 2023 10:48
@BvB93

BvB93 commented Jun 6, 2023

Copy link
Copy Markdown
Member Author

Marking as draft for now until I have time to take a closer look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BvB93 BvB93 mentioned this pull request Jun 21, 2023
TYP: modelling various integer types as a specialized version of the generic class breaks type-checking in pyright #23007
Closed
@rgommers

rgommers commented Aug 7, 2023

Copy link
Copy Markdown
Member

It's annoying that this has now become an issue all of a sudden, though I wonder if we could run mypy directly against the numpy source? The .pyi files aren't affected by the build stage after all.

It should sorta work I think; the exceptions like generated .py/.pyi files are corner cases where there may be issues. The tests under numpy/typing/ import numpy though, so they'll work with editable installs and spin test, but not with a regular installed package.

That Mypy issue is a bit sad of course; they can/should just fix the thing where typing_extensions being installed breaks things for them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Aug 15, 2023

Copy link
Copy Markdown
Member

I tried to add a Mypy run with Python 3.12.0rc1 (as part of gh-24291), but it chokes on:

 ERROR numpy/typing/tests/test_typing.py - DeprecationWarning: ast.Bytes is deprecated and will be removed in Python 3.14; use ast.Constant instead

I suspect that this Mypy upgrade will fix that, so I haven't bothered to look at it in more detail.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BvB93
BvB93 force-pushed the mypy branch from a6e59dd to 1320679 Compare August 23, 2023 13:32
BvB93 added 6 commits August 23, 2023 19:20
@BvB93
CI,TYP: Bump mypy to 1.3.0
a0c70f3
@BvB93
TYP: Improve function-based annotations with typing.Concatenate
4a74d38
@BvB93
CI: Avoid overriding MYPYPATH
9b636a1
This practice is actively discouraged by mypy
@BvB93
TYP: Bump mypy to 1.5.1
1be0c4c
@BvB93
TYP: Lower the mypy pin to 1.4.1
f23c5ae
@BvB93
TYP,TST: Adapt the typing test suite to mypy >=1.4 changes
6f52ecb
@BvB93
BvB93 force-pushed the mypy branch from 1320679 to 6f52ecb Compare August 23, 2023 17:37
@BvB93 BvB93 changed the title CI,TYP: Bump mypy to 1.3.0 CI,TYP: Bump mypy to 1.4.1 Aug 23, 2023
@BvB93
BvB93 marked this pull request as ready for review August 23, 2023 18:35
@BvB93

BvB93 commented Aug 23, 2023

Copy link
Copy Markdown
Member Author

Right, have yet to get mypy 1.5.1 to cooperate, but 1.4.1 now works making this PR good to go.

Mypy 1.5.1 seems to truncate its type evaluation before all fail-related tests are completed, which causes issue. I suspect that this is related to the new "Consistently Avoid Type Checking Unreachable Code" improvements (1.5.1 changelog); hopefully this is something that can be fixed by implementing #21505 via useage of typing.assert_type and .assert_never.

rgommers reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rgommers
rgommers approved these changes Aug 24, 2023
View reviewed changes

@rgommers rgommers left a comment

Copy link
Copy Markdown
Member

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 looks great, thanks @BvB93. After going through the changes, the one thing that stood out to me was the "Union of scalars" thing which looks like a regression. But then I saw that you already explained it:

In addition to mypy now having implemented support for typing.Concatenate there seems been some changes in how it deals with the joining of super- and sub-classes. The end result as that, e.g. the likes of np.float64 + np.float32 were previously interpreted as producing np.floating[_64Bit] while not it results in a np.floating[_64Bit | _32Bit] union.

While non-ideal, this upstream change is admitetly a minor inconvenience in the grand scheme of things, mostly because the typing of dtype bitsizes in numpy is severely lacking due to the sheer number of challenges associated with it.

Fair enough, I agree it's a minor thing and we can simply ignore it for now.

I'll put back the typing_extensions requirement in environment.yml and then this should be good to go.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rgommers
TYP: guard typing_extensions usage for <py310, add it back in envir…
8de2ed5
…onment.yml

It's still needed, so keep it in the environment. The added import
guards here match the ones already present in two other `.pyi` files.

[skip cirrus] [skip circle] [skip azp] [skip travis]
@rgommers rgommers added this to the 2.0.0 release milestone Aug 24, 2023
@rgommers

rgommers commented Aug 24, 2023

Copy link
Copy Markdown
Member

I found another small issue with the use of typing_extensions - pushed a fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BvB93

BvB93 commented Aug 24, 2023

Copy link
Copy Markdown
Member Author

I found another small issue with the use of typing_extensions - pushed a fix.

Thanks Ralf. Considering typing_extensions isn't used during runtime anymore (only while static type checking) I'm not 100% sure whether it's worthwhile to even keep it around, as we're sort-of-but-not-fully managing a mypy dependency (the two are very tightly intertwined as far as lower version bounds are concerned).

In any case, keeping it for now can't hurt either way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Aug 25, 2023

Copy link
Copy Markdown
Member

We're almost at the end of the support window for Python 3.9; once we drop it, the last usages of typing_extensions will be automatically cleaned up. So let's just leave it alone until then?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers
rgommers merged commit 4b849d4 into numpy:main Aug 25, 2023
@rgommers

rgommers commented Aug 25, 2023

Copy link
Copy Markdown
Member

Okay, in it goes. Thanks Bas!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charris charris mentioned this pull request Aug 25, 2023
CI,TYP: Bump mypy to 1.4.1 #24541
Merged
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 25, 2023
@charris charris removed this from the 2.0.0 release milestone Aug 25, 2023
@BvB93
BvB93 deleted the mypy branch September 6, 2023 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seberg seberg seberg left review comments
@rgommers rgommers rgommers approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

41 - Static typing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@BvB93 @seberg @rgommers @charris
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.