fix IntEnum is not accepted when floats are required #2272#2276
Closed
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
Closed
fix IntEnum is not accepted when floats are required #2272#2276asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #2272 where IntEnum values were incorrectly rejected when passed to functions expecting float parameters. The fix generalizes the numeric tower implementation to accept any subclass of int where float is required, and any subclass of int or float where complex is required.
Changes:
- Updated numeric tower type checking logic to use inheritance-based checks instead of hardcoded builtin type checks
- Added regression test for
IntEnumtofloatassignment - Updated Cargo.lock with dependency checksum
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyrefly/lib/solver/subset.rs | Generalized numeric tower checks to accept any subclass of int/float instead of specific builtin types |
| pyrefly/lib/test/enums.rs | Added regression test verifying IntEnum values can be passed to float parameters |
| Cargo.lock | Updated dependency checksum for backtrace crate |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: asynq (https://github.com/quora/asynq)
- ERROR asynq/tests/test_profiler.py:59:20-46: `/` is not supported between `float` and `Utime` [unsupported-operation]
- ::error file=asynq/tests/test_profiler.py,line=59,col=20,endLine=59,endColumn=46,title=Pyrefly unsupported-operation::`/` is not supported between `float` and `Utime`%0A Argument `Utime` is not assignable to parameter `value` with type `float` in function `float.__truediv__`
hydpy (https://github.com/hydpy-dev/hydpy)
- ERROR hydpy/core/timetools.py:264:47-74: Argument `OptionContextInt` is not assignable to parameter `minutes` with type `float` in function `datetime.timedelta.__new__` [bad-argument-type]
- ERROR hydpy/models/lland_dd.py:2506:38-58: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_dd.py:2508:50-76: Argument `tuple[IntConstant, IntConstant, IntConstant, IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_knauf.py:2131:53-73: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_knauf.py:2134:44-70: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_knauf_ic.py:1892:53-73: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_knauf_ic.py:1895:44-70: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ERROR hydpy/models/lland_knauf_ic.py:1897:54-77: Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin` [bad-argument-type]
- ::error file=hydpy/core/timetools.py,line=264,col=47,endLine=264,endColumn=74,title=Pyrefly bad-argument-type::Argument `OptionContextInt` is not assignable to parameter `minutes` with type `float` in function `datetime.timedelta.__new__`
- ::error file=hydpy/models/lland_dd.py,line=2506,col=38,endLine=2506,endColumn=58,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_dd.py,line=2508,col=50,endLine=2508,endColumn=76,title=Pyrefly bad-argument-type::Argument `tuple[IntConstant, IntConstant, IntConstant, IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_knauf.py,line=2131,col=53,endLine=2131,endColumn=73,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_knauf.py,line=2134,col=44,endLine=2134,endColumn=70,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_knauf_ic.py,line=1892,col=53,endLine=1892,endColumn=73,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_knauf_ic.py,line=1895,col=44,endLine=1895,endColumn=70,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
- ::error file=hydpy/models/lland_knauf_ic.py,line=1897,col=54,endLine=1897,endColumn=77,title=Pyrefly bad-argument-type::Argument `list[IntConstant]` is not assignable to parameter `test_elements` with type `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype[Any]]] | _SupportsArray[dtype[Any]] | bytes | complex | str` in function `numpy.lib._arraysetops_impl.isin`
pydantic (https://github.com/pydantic/pydantic)
- ERROR pydantic/types.py:2182:16-31: `/` is not supported between `Self@ByteSize` and `float` [unsupported-operation]
- ::error file=pydantic/types.py,line=2182,col=16,endLine=2182,endColumn=31,title=Pyrefly unsupported-operation::`/` is not supported between `Self@ByteSize` and `float`%0A Argument `float` is not assignable to parameter `value` with type `int` in function `int.__truediv__`
colour (https://github.com/colour-science/colour)
- ERROR colour/algebra/tests/test_common.py:204:57-68: No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]]) [no-matching-overload]
- ERROR colour/algebra/tests/test_common.py:210:57-68: No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]]) [no-matching-overload]
- ERROR colour/constants/common.py:49:40-51: No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]]) [no-matching-overload]
- ERROR colour/geometry/section.py:151:33-45: No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], type[float64]) [no-matching-overload]
- ::error file=colour/algebra/tests/test_common.py,line=204,col=57,endLine=204,endColumn=68,title=Pyrefly no-matching-overload::No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]])%0A Possible overloads:%0A (cls: type[finfo[_FloatingT_co]], dtype: _HasDType[dtype[_FloatingT_co]] | _HasNumPyDType[dtype[_FloatingT_co]] | dtype[_FloatingT_co] | _FloatingT_co | type[_FloatingT_co]) -> finfo[_FloatingT_co] [closest match]%0A (cls: type[finfo[_FloatingT_co]], dtype: _Float16Codes) -> finfo[floating[_16Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c8', '<f4', '=c8', '=f4', '>c8', '>f4', 'c8', 'complex64', 'f4', 'float32', '|c8', '|f4'] | _HasDType[dtype[complexfloating[_32Bit, _32Bit]]] | _HasNumPyDType[dtype[complexfloating[_32Bit, _32Bit]]] | dtype[complexfloating[_32Bit, _32Bit]] | type[complexfloating[_32Bit, _32Bit]]) -> finfo[floating[_32Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c16', '<f8', '=c16', '=f8', '>c16', '>f8', 'c16', 'complex128', 'f8', 'float64', '|c16', '|f8'] | complex | type[complex]) -> finfo[float64]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<G', '<g', '=G', '=g', '>G', '>g', 'G', 'clongdouble', 'g', 'longdouble', '|G', '|g'] | _HasDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | _HasNumPyDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]] | type[complexfloating[_NBitLongDouble, _NBitLongDouble]]) -> finfo[floating[_NBitLongDouble]]%0A (cls: type[finfo[_FloatingT_co]], dtype: str) -> finfo[floating[Any]]
- ::error file=colour/algebra/tests/test_common.py,line=210,col=57,endLine=210,endColumn=68,title=Pyrefly no-matching-overload::No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]])%0A Possible overloads:%0A (cls: type[finfo[_FloatingT_co]], dtype: _HasDType[dtype[_FloatingT_co]] | _HasNumPyDType[dtype[_FloatingT_co]] | dtype[_FloatingT_co] | _FloatingT_co | type[_FloatingT_co]) -> finfo[_FloatingT_co] [closest match]%0A (cls: type[finfo[_FloatingT_co]], dtype: _Float16Codes) -> finfo[floating[_16Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c8', '<f4', '=c8', '=f4', '>c8', '>f4', 'c8', 'complex64', 'f4', 'float32', '|c8', '|f4'] | _HasDType[dtype[complexfloating[_32Bit, _32Bit]]] | _HasNumPyDType[dtype[complexfloating[_32Bit, _32Bit]]] | dtype[complexfloating[_32Bit, _32Bit]] | type[complexfloating[_32Bit, _32Bit]]) -> finfo[floating[_32Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c16', '<f8', '=c16', '=f8', '>c16', '>f8', 'c16', 'complex128', 'f8', 'float64', '|c16', '|f8'] | complex | type[complex]) -> finfo[float64]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<G', '<g', '=G', '=g', '>G', '>g', 'G', 'clongdouble', 'g', 'longdouble', '|G', '|g'] | _HasDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | _HasNumPyDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]] | type[complexfloating[_NBitLongDouble, _NBitLongDouble]]) -> finfo[floating[_NBitLongDouble]]%0A (cls: type[finfo[_FloatingT_co]], dtype: str) -> finfo[floating[Any]]
- ::error file=colour/constants/common.py,line=49,col=40,endLine=49,endColumn=51,title=Pyrefly no-matching-overload::No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], TypeAlias[double, type[float64]])%0A Possible overloads:%0A (cls: type[finfo[_FloatingT_co]], dtype: _HasDType[dtype[_FloatingT_co]] | _HasNumPyDType[dtype[_FloatingT_co]] | dtype[_FloatingT_co] | _FloatingT_co | type[_FloatingT_co]) -> finfo[_FloatingT_co] [closest match]%0A (cls: type[finfo[_FloatingT_co]], dtype: _Float16Codes) -> finfo[floating[_16Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c8', '<f4', '=c8', '=f4', '>c8', '>f4', 'c8', 'complex64', 'f4', 'float32', '|c8', '|f4'] | _HasDType[dtype[complexfloating[_32Bit, _32Bit]]] | _HasNumPyDType[dtype[complexfloating[_32Bit, _32Bit]]] | dtype[complexfloating[_32Bit, _32Bit]] | type[complexfloating[_32Bit, _32Bit]]) -> finfo[floating[_32Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c16', '<f8', '=c16', '=f8', '>c16', '>f8', 'c16', 'complex128', 'f8', 'float64', '|c16', '|f8'] | complex | type[complex]) -> finfo[float64]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<G', '<g', '=G', '=g', '>G', '>g', 'G', 'clongdouble', 'g', 'longdouble', '|G', '|g'] | _HasDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | _HasNumPyDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]] | type[complexfloating[_NBitLongDouble, _NBitLongDouble]]) -> finfo[floating[_NBitLongDouble]]%0A (cls: type[finfo[_FloatingT_co]], dtype: str) -> finfo[floating[Any]]
- ::error file=colour/geometry/section.py,line=151,col=33,endLine=151,endColumn=45,title=Pyrefly no-matching-overload::No matching overload found for function `numpy._core.getlimits.finfo.__new__` called with arguments: (type[finfo[_FloatingT_co]], type[float64])%0A Possible overloads:%0A (cls: type[finfo[_FloatingT_co]], dtype: _HasDType[dtype[_FloatingT_co]] | _HasNumPyDType[dtype[_FloatingT_co]] | dtype[_FloatingT_co] | _FloatingT_co | type[_FloatingT_co]) -> finfo[_FloatingT_co] [closest match]%0A (cls: type[finfo[_FloatingT_co]], dtype: _Float16Codes) -> finfo[floating[_16Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c8', '<f4', '=c8', '=f4', '>c8', '>f4', 'c8', 'complex64', 'f4', 'float32', '|c8', '|f4'] | _HasDType[dtype[complexfloating[_32Bit, _32Bit]]] | _HasNumPyDType[dtype[complexfloating[_32Bit, _32Bit]]] | dtype[complexfloating[_32Bit, _32Bit]] | type[complexfloating[_32Bit, _32Bit]]) -> finfo[floating[_32Bit]]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<c16', '<f8', '=c16', '=f8', '>c16', '>f8', 'c16', 'complex128', 'f8', 'float64', '|c16', '|f8'] | complex | type[complex]) -> finfo[float64]%0A (cls: type[finfo[_FloatingT_co]], dtype: Literal['<G', '<g', '=G', '=g', '>G', '>g', 'G', 'clongdouble', 'g', 'longdouble', '|G', '|g'] | _HasDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | _HasNumPyDType[dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]]] | dtype[complexfloating[_NBitLongDouble, _NBitLongDouble]] | type[complexfloating[_NBitLongDouble, _NBitLongDouble]]) -> finfo[floating[_NBitLongDouble]]%0A (cls: type[finfo[_FloatingT_co]], dtype: str) -> finfo[floating[Any]]
|
yangdanny97
approved these changes
Feb 4, 2026
Contributor
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2272
Updated the numeric tower check to treat any int subclass (including IntEnum) as assignable to float, and extended the complex case to accept subclasses of int/float.
Test Plan
Added a regression test covering IntEnum to float calls.