-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Overload bool.__new/bool__ for Literal bools #10465
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
|
Is there a way to see the projects this affects using mypy-primer using my mypy branch? |
The easiest way would be to temporarily push a commit to your mypy PR that makes these edits to |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <[email protected]>
|
python/mypy#15687 (comment) changes don't appear to be causing any problems |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Still waiting for python/mypy#15687. |
This comment has been minimized.
This comment has been minimized.
Unblocks python/typeshed#10465 --------- Co-authored-by: Ivan Levkivskyi <[email protected]>
|
Is there a way to run this with mypy dev? @srittau |
|
@Gobot1234 You could just temporarily change the mypy version in |
This comment has been minimized.
This comment has been minimized.
|
I've removed the "deferred" marker. We might be able to suppress mypy's warnings, although we should add some tests to ensure that mypy still works correctly despite that. |
Where do you want these? |
You could add a |
|
Diff from mypy_primer, showing the effect of this PR on open source code: nionutils (https://github.com/nion-software/nionutils)
+ nion/utils/Geometry.py:406: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:412: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:522: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:528: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:696: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:702: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:823: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:829: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:965: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:971: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:1145: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/Geometry.py:1151: error: Returning Any from function declared to return "bool" [no-any-return]
+ nion/utils/ListModel.py:199: error: Returning Any from function declared to return "bool" [no-any-return]
packaging (https://github.com/pypa/packaging)
+ src/packaging/_manylinux.py:194: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/packaging/_manylinux.py:197: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/packaging/_manylinux.py:201: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/packaging/_manylinux.py:205: error: Returning Any from function declared to return "bool" [no-any-return]
mypy (https://github.com/python/mypy)
+ mypy/stubtest.py:1438: error: Returning Any from function declared to return "bool" [no-any-return]
colour (https://github.com/colour-science/colour)
+ colour/continuous/signal.py:835: error: Argument 1 to "bool" has incompatible type "numpy.bool[builtins.bool]"; expected "_Truthy" [arg-type]
+ colour/continuous/signal.py:835: note: Following member(s) of "numpy.bool[builtins.bool]" have conflicts:
+ colour/continuous/signal.py:835: note: Expected:
+ colour/continuous/signal.py:835: note: def __bool__(self) -> Literal[True]
+ colour/continuous/signal.py:835: note: Got:
+ colour/continuous/signal.py:835: note: def __bool__(self) -> bool
+ colour/colorimetry/spectrum.py:415: error: Argument 1 to "bool" has incompatible type "numpy.bool[builtins.bool]"; expected "_Truthy" [arg-type]
+ colour/colorimetry/spectrum.py:415: note: Following member(s) of "numpy.bool[builtins.bool]" have conflicts:
+ colour/colorimetry/spectrum.py:415: note: Expected:
+ colour/colorimetry/spectrum.py:415: note: def __bool__(self) -> Literal[True]
+ colour/colorimetry/spectrum.py:415: note: Got:
+ colour/colorimetry/spectrum.py:415: note: def __bool__(self) -> bool
pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/gdblib/events.py:271: error: Need type annotation for "paused" [var-annotated]
dulwich (https://github.com/dulwich/dulwich)
+ dulwich/sparse_patterns.py:186: error: Returning Any from function declared to return "bool" [no-any-return]
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/metaschema.py: note: In member "__eq__" of class "ArraySchema":
+ schema_salad/metaschema.py:1959:13: error: Returning Any from function declared to return "bool" [no-any-return]
+ schema_salad/metaschema.py: note: In member "__eq__" of class "MapSchema":
+ schema_salad/metaschema.py:2158:13: error: Returning Any from function declared to return "bool" [no-any-return]
+ schema_salad/metaschema.py: note: In member "__eq__" of class "UnionSchema":
+ schema_salad/metaschema.py:2357:13: error: Returning Any from function declared to return "bool" [no-any-return]
+ schema_salad/metaschema.py: note: In member "__eq__" of class "SpecializeDef":
+ schema_salad/metaschema.py:3300:13: error: Returning Any from function declared to return "bool" [no-any-return]
+ schema_salad/tests/test_ref_resolver.py: note: In function "test_attachments":
+ schema_salad/tests/test_ref_resolver.py:222:9: error: Returning Any from function declared to return "bool" [no-any-return]
+ schema_salad/tests/test_ref_resolver.py:233:9: error: Returning Any from function declared to return "bool" [no-any-return]
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/ethereum/airdrops.py:731: error: Need type annotation for "addresses_claims" [var-annotated]
spack (https://github.com/spack/spack)
+ lib/spack/spack/database.py:1247: error: Incompatible types in assignment (expression has type "bool", variable has type "Literal[True]") [assignment]
+ lib/spack/spack/database.py:1318: error: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True]") [assignment]
+ lib/spack/spack/database.py:1385: error: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True]") [assignment]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/ssl_match_hostname.py:53: error: Returning Any from function declared to return "Match[str] | bool | None" [no-any-return]
+ src/urllib3/contrib/emscripten/fetch.py:694: error: Returning Any from function declared to return "bool" [no-any-return]
core (https://github.com/home-assistant/core)
+ homeassistant/helpers/template/__init__.py:1384: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/recorder/purge.py:132: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/alexa/config.py:162: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/alexa/smart_home.py:90: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/uvc/camera.py:142: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/nissan_leaf/__init__.py:472: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/music_assistant/entity.py:72: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/lifx/coordinator.py:173: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/lifx/coordinator.py:185: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/lifx/coordinator.py:584: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/climate/device_condition.py:96: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/climate/device_condition.py:98: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/bond/utils.py:242: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/bluetooth/config_flow.py:240: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/auth/mfa_modules/totp.py:177: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/auth/mfa_modules/notify.py:77: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/helpers/template/extensions/devices.py:139: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wemo/config_flow.py:21: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/laundrify/binary_sensor.py:76: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/hyperion/switch.py:172: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/hyperion/switch.py:178: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/hyperion/sensor.py:135: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/hyperion/light.py:196: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/hyperion/config_flow.py:293: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/hyperion/camera.py:153: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/gios/sensor.py:248: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/ecowitt/binary_sensor.py:79: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/entity.py:229: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/binary_sensor.py:502: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/squeezebox/media_player.py:340: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/squeezebox/media_player.py:414: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/squeezebox/binary_sensor.py:103: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/rfxtrx/cover.py:31: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/ping/device_tracker.py:85: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/nissan_leaf/switch.py:68: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/nissan_leaf/binary_sensor.py:64: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/nissan_leaf/binary_sensor.py:90: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/lifx/light.py:166: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/isy994/switch.py:93: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/switch.py:121: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/isy994/switch.py:185: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/fan.py:76: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/fan.py:120: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/isy994/cover.py:67: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/cover.py:94: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/isy994/binary_sensor.py:261: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/binary_sensor.py:531: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/incomfort/binary_sensor.py:104: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/android_ip_webcam/switch.py:151: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/switch.py:80: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/siren.py:83: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/light.py:208: error: Right operand of "or" is never evaluated [unreachable]
+ homeassistant/components/zwave_js/fan.py:145: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/device_condition.py:173: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/device_condition.py:183: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/device_condition.py:193: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/zwave_js/cover.py:146: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/cover.py:464: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/cover.py:471: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/zwave_js/cover.py:485: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/yale_smart_alarm/binary_sensor.py:76: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/yale_smart_alarm/binary_sensor.py:120: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/unifi/button.py:55: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/tplink/config_flow.py:315: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/romy/binary_sensor.py:73: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/nut/switch.py:76: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/isy994/lock.py:110: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/fritzbox/sensor.py:73: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/flux_led/number.py:165: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/flux_led/switch.py:103: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/knx/switch.py:92: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/knx/light.py:331: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/ecovacs/binary_sensor.py:120: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/comelit/switch.py:85: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/comelit/light.py:71: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/abode/switch.py:93: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/abode/lock.py:48: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/abode/light.py:75: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wled/switch.py:70: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wled/switch.py:102: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wled/switch.py:134: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wled/light.py:80: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/wled/light.py:213: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/uptimerobot/switch.py:66: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/uptimerobot/binary_sensor.py:56: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/shelly/switch.py:431: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/shelly/switch.py:479: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/shelly/light.py:159: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/shelly/light.py:389: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/rest/sensor.py:150: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/rest/binary_sensor.py:143: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/switch.py:167: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/switch.py:173: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/switch.py:186: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/switch.py:198: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/select.py:137: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/number.py:127: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/climate.py:527: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/climate.py:538: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/climate.py:549: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/climate.py:560: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/climate.py:571: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/sensibo/button.py:95: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/homee/switch.py:126: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/homee/light.py:179: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/homee/binary_sensor.py:202: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/fully_kiosk/binary_sensor.py:71: error: Returning Any from function declared to return "bool | None" [no-any-return]
+ homeassistant/components/synology_dsm/camera.py:123: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/synology_dsm/binary_sensor.py:149: error: Returning Any from function declared to return "bool" [no-any-return]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/type_clinic.py:770: error: Statement is unreachable [unreachable]
poetry (https://github.com/python-poetry/poetry)
+ src/poetry/console/commands/install.py:107: error: Returning Any from function declared to return "bool" [no-any-return]
starlette (https://github.com/encode/starlette)
+ tests/test_config.py:25: error: Expression is of type "Literal[True]", not "bool" [assert-type]
+ tests/test_config.py:27: error: Expression is of type "Literal[True] | None", not "bool | None" [assert-type]
pylint (https://github.com/pycqa/pylint)
+ pylint/pyreverse/diadefslib.py:82: error: Returning Any from function declared to return "bool" [no-any-return]
+ pylint/checkers/variables.py:2195: error: Returning Any from function declared to return "bool" [no-any-return]
+ pylint/checkers/variables.py:2203: error: Returning Any from function declared to return "bool" [no-any-return]
bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch/tests/test_utils.py: note: In function "test_rewrite":
+ src/bandersnatch/tests/test_utils.py:81: error: Statement is unreachable [unreachable]
+ src/bandersnatch_storage_plugins/s3.py: note: In member "is_locked" of class "S3FileLock":
+ src/bandersnatch_storage_plugins/s3.py:114: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/bandersnatch_storage_plugins/s3.py: note: In member "exists" of class "S3Storage":
+ src/bandersnatch_storage_plugins/s3.py:414: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/bandersnatch_storage_plugins/s3.py: note: In member "is_dir" of class "S3Storage":
+ src/bandersnatch_storage_plugins/s3.py:419: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/bandersnatch_storage_plugins/s3.py: note: In member "is_file" of class "S3Storage":
+ src/bandersnatch_storage_plugins/s3.py:424: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/bandersnatch_storage_plugins/s3.py: note: In member "is_symlink" of class "S3Storage":
+ src/bandersnatch_storage_plugins/s3.py:429: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/bandersnatch/tests/plugins/test_prerelease_name.py: note: In member "_check_filter" of class "TestRegexReleaseFilter":
+ src/bandersnatch/tests/plugins/test_prerelease_name.py:80: error: Returning Any from function declared to return "bool" [no-any-return]
jax (https://github.com/google/jax)
+ jax/_src/api_util.py:347: error: Incompatible types in assignment (expression has type "bool", variable has type "Literal[True]") [assignment]
cloud-init (https://github.com/canonical/cloud-init)
+ cloudinit/net/openbsd.py:46: error: Statement is unreachable [unreachable]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/mark/expression.py:353: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/_pytest/terminal.py:446: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/_pytest/terminal.py:450: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/_pytest/fixtures.py:1079: error: Incompatible types in assignment (expression has type "bool", variable has type "Literal[True]") [assignment]
+ src/_pytest/fixtures.py:1089: error: Statement is unreachable [unreachable]
+ testing/test_pathlib.py:120: error: Returning Any from function declared to return "bool" [no-any-return]
PyWinCtl (https://github.com/Kalmat/PyWinCtl)
+ src/pywinctl/_pywinctl_linux.py:662: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/pywinctl/_pywinctl_linux.py:672: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/pywinctl/_pywinctl_linux.py:781: error: Returning Any from function declared to return "bool" [no-any-return]
+ src/pywinctl/_pywinctl_linux.py:813: error: Returning Any from function declared to return "bool" [no-any-return]
|
Inspired by microsoft/pyright#5515
Closes #6069