Skip to content

Comments

[ty] bytes literal is a sequence of integers#23329

Merged
AlexWaygood merged 1 commit intomainfrom
cjm/bytes-iterable
Feb 16, 2026
Merged

[ty] bytes literal is a sequence of integers#23329
AlexWaygood merged 1 commit intomainfrom
cjm/bytes-iterable

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Feb 16, 2026

Summary

Mirror our existing handling for understanding that string literals are a sequence of specific characters -- bytes literals are a sequence of specific integers.

Test Plan

Added mdtest.

@carljm carljm added the ty Multi-file analysis & type inference label Feb 16, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 16, 2026

Typing conformance results

No changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 16, 2026

mypy_primer results

Changes were detected when running on open source projects
spack (https://github.com/spack/spack)
- lib/spack/spack/detection/path.py:169:33: error[invalid-argument-type] Argument to function `dedupe_paths` is incorrect: Expected `list[str]`, found `Unknown | list[int | str | bytes | ... omitted 3 union elements]`
+ lib/spack/spack/detection/path.py:169:33: error[invalid-argument-type] Argument to function `dedupe_paths` is incorrect: Expected `list[str]`, found `Unknown | list[int | str | PathLike[str] | ... omitted 3 union elements]`

rich (https://github.com/Textualize/rich)
- tests/test_tools.py:17:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, Unknown | str]]`
+ tests/test_tools.py:17:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, str | Unknown]]`
- tests/test_tools.py:18:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, Unknown | str]]`
+ tests/test_tools.py:18:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, str | Unknown]]`
- tests/test_tools.py:19:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, Unknown | str]]`
+ tests/test_tools.py:19:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, str | Unknown]]`
- tests/test_tools.py:20:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, Unknown | str]]`
+ tests/test_tools.py:20:17: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Iterable[tuple[bool, str | Unknown]]`

artigraph (https://github.com/artigraph/artigraph)
- tests/arti/types/test_types.py:100:51: error[invalid-argument-type] Argument is incorrect: Expected `frozenset[Any]`, found `frozenset[float | Unknown | int] | list[int | Unknown | float] | tuple[float | Unknown | int, ...]`
+ tests/arti/types/test_types.py:100:51: error[invalid-argument-type] Argument is incorrect: Expected `frozenset[Any]`, found `frozenset[float | Unknown | int] | list[Unknown | int | float] | tuple[float | Unknown | int, ...]`

meson (https://github.com/mesonbuild/meson)
- mesonbuild/dependencies/cuda.py:137:76: error[invalid-argument-type] Argument to function `version_compare_many` is incorrect: Expected `str`, found `str | None | Unknown`
+ mesonbuild/dependencies/cuda.py:137:76: error[invalid-argument-type] Argument to function `version_compare_many` is incorrect: Expected `str`, found `Unknown | str | None`

cloud-init (https://github.com/canonical/cloud-init)
- tests/unittests/distros/test_user_data_normalize.py:24:31: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `dict[Unknown, Unknown]`, found `Unknown | bool | list[Unknown] | ... omitted 3 union elements`
+ tests/unittests/distros/test_user_data_normalize.py:24:31: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `dict[Unknown, Unknown]`, found `Unknown | dict[Unknown | str, Unknown | str] | str | ... omitted 3 union elements`
- tests/unittests/sources/test_gce.py:71:31: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `dict[Unknown, Unknown]`, found `Unknown | bool | list[Unknown] | ... omitted 3 union elements`
+ tests/unittests/sources/test_gce.py:71:31: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `dict[Unknown, Unknown]`, found `Unknown | dict[Unknown | str, Unknown | str] | str | ... omitted 3 union elements`

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 50 diagnostics
+ Found 51 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `Unknown | Coroutine[Any, Any, Unknown]`
+ src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler] | Coroutine[Any, Any, T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]]`

scikit-learn (https://github.com/scikit-learn/scikit-learn)
- sklearn/datasets/_lfw.py:469:60: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `bytes | bytearray`, found `Unknown | str`
+ sklearn/datasets/_lfw.py:469:60: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `bytes | bytearray`, found `str | Unknown`

sympy (https://github.com/sympy/sympy)
- sympy/parsing/mathematica.py:692:38: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | list[Unknown | str]`
- Found 15981 diagnostics
+ Found 15980 diagnostics

rotki (https://github.com/rotki/rotki)
- rotkehlchen/tests/unit/test_makerdao.py:170:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | dict[Unknown | str, Unknown | Balance] | Unknown]`
+ rotkehlchen/tests/unit/test_makerdao.py:170:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | Unknown | dict[Unknown | str, Unknown | Balance]]`
- rotkehlchen/tests/unit/test_makerdao.py:171:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | dict[Unknown | str, Unknown | Balance] | Unknown]`
+ rotkehlchen/tests/unit/test_makerdao.py:171:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | Unknown | dict[Unknown | str, Unknown | Balance]]`

jax (https://github.com/google/jax)
- jax/_src/export/_export.py:1376:45: error[invalid-argument-type] Argument to function `_get_named_sharding` is incorrect: Expected `ShapedArray`, found `AbstractValue | Unknown`
+ jax/_src/export/_export.py:1376:45: error[invalid-argument-type] Argument to function `_get_named_sharding` is incorrect: Expected `ShapedArray`, found `Unknown | AbstractValue`
- jax/collect_profile.py:110:17: error[unresolved-attribute] Attribute `glob` is not defined on `PathLike[str]`, `int`, `str`, `bytes`, `PathLike[bytes]` in union `Unknown | PathLike[str] | int | ... omitted 3 union elements`
+ jax/collect_profile.py:110:17: error[unresolved-attribute] Attribute `glob` is not defined on `PathLike[str]`, `int`, `str`, `bytes`, `PathLike[bytes]` in union `PathLike[str] | Unknown | int | ... omitted 3 union elements`
- jax/collect_profile.py:113:22: error[unsupported-operator] Operator `/` is not supported between objects of type `Unknown | PathLike[str] | int | ... omitted 3 union elements` and `Literal["remote.trace.json.gz"]`
+ jax/collect_profile.py:113:22: error[unsupported-operator] Operator `/` is not supported between objects of type `PathLike[str] | Unknown | int | ... omitted 3 union elements` and `Literal["remote.trace.json.gz"]`

colour (https://github.com/colour-science/colour)
+ colour/utilities/verbose.py:1071:69: error[invalid-argument-type] Argument to function `getattr` is incorrect: Expected `str`, found `bool | (Unknown & ~None) | <class 'str'>`
- colour/utilities/verbose.py:1071:69: error[invalid-argument-type] Argument to function `getattr` is incorrect: Expected `str`, found `(Unknown & ~None) | <class 'str'> | bool`

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 16, 2026

Memory usage report

Memory usage unchanged ✅

@carljm carljm marked this pull request as ready for review February 16, 2026 07:14
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 16, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
unresolved-attribute 0 0 17
invalid-argument-type 0 1 14
unsupported-operator 0 0 2
invalid-return-type 1 0 0
Total 1 1 33

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood merged commit 987a7dd into main Feb 16, 2026
52 checks passed
@AlexWaygood AlexWaygood deleted the cjm/bytes-iterable branch February 16, 2026 10:03
@AlexWaygood
Copy link
Member

FWIW, I tried to see if there was a way to reduce the code duplication here, but it seemed to result in a slowdown, so I concluded it was not worth it: #23344

carljm added a commit that referenced this pull request Feb 16, 2026
* main: (43 commits)
  [`ruff`] Suppress diagnostic for strings with backslashes in interpolations before Python 3.12 (`RUF027`) (#21069)
  [flake8-bugbear] Fix B023 false positive for immediately-invoked lambdas (#23294)
  [ty] Add `Final` mdtests for loops and redeclaration (#23331)
  [`flake8-pyi`] Also check string annotations (`PYI041`) (#19023)
  Remove AlexWaygood as a flake8-pyi codeowner (#23347)
  [ty] Add comments to clarify the purpose of `NominalInstanceType::class_name` and `NominalInstanceType::class_module_name` (#23339)
  Add attestations for release artifacts and Docker images (#23111)
  [ty] Fix `assert_type` diagnostic messages (#23342)
  [ty] Force-update all insta snapshots (#23343)
  Add Q004 to the list of conflicting rules (#23340)
  [ty] Fix `invalid-match-pattern` false positives (#23338)
  [ty] new diagnostic called-match-pattern-must-be-a-type (#22939)
  [ty] Update flaky projects  (#23337)
  [ty] Increase timeout for ecosystem report to 40 min (#23336)
  Bump ecosystem-analyzer pin  (#23335)
  [ty] Replace `strsim` with CPython-based Levenshtein implementation (#23291)
  [ty] Add mdtest for staticmethod assigned in class body (#23330)
  [ty] fix inferring type variable from string literal argument (#23326)
  [ty] bytes literal is a sequence of integers (#23329)
  Update rand and getrandom (#23333)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants