Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jorenham
Copy link
Member

See python/mypy#19732 (comment) for context

@jorenham jorenham added stubs: Incorrect numpy.generic port: to numpy NumType PR's that should be ported to NumPy labels Aug 26, 2025
@jorenham jorenham added this to the v2.3.x.x milestone Aug 26, 2025
@jorenham jorenham force-pushed the mypy-1.18.0+dev-stubtest-fixes branch from d9f1255 to a089fe9 Compare August 26, 2025 17:14
@jorenham jorenham requested a review from Copilot August 26, 2025 17:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces __init__ methods with __new__ methods for NumPy scalar types to address MyPy compatibility issues (see referenced GitHub issue). The change aligns the type stubs with Python's scalar type instantiation patterns where __new__ is responsible for instance creation.

  • Replaces __init__ with __new__ across all scalar type classes
  • Updates method signatures to return Self or specific type instances instead of None
  • Adds test cases for abstract base classes to ensure they cannot be instantiated

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/numpy-stubs/init.pyi Replaces __init__ with __new__ for all scalar types, updates signatures and parameter names
src/numpy-stubs/@test/static/reject/scalars.pyi Adds test cases for abstract base classes that should reject instantiation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jorenham jorenham merged commit f861870 into main Aug 26, 2025
20 checks passed
@jorenham jorenham deleted the mypy-1.18.0+dev-stubtest-fixes branch August 26, 2025 17:17
jorenham added a commit to jorenham/numpy that referenced this pull request Aug 26, 2025
@jorenham jorenham removed the port: to numpy NumType PR's that should be ported to NumPy label Aug 27, 2025
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request Sep 10, 2025
charris pushed a commit to charris/numpy that referenced this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants