Skip to content

Conversation

@michaelm-openai
Copy link
Contributor

@michaelm-openai michaelm-openai commented Jan 13, 2026

Fixes #11001

Related to typing python/typing#256

Expected behavior changes under this flag:

  • str and its subtypes are no longer treated as subtypes of Collection, Iterable, Sequence or protocols that extend them. Assignment and argument passing will be treated as errors.
  • The builtin iter() method has an additional overload which accepts str. This is the recommended way to iterate over characters when this flag is enabled.
  • Invalid assignment of str to subtypes of Container, such as Collection will not report a conflict on the __contains__ method, since this introduces noise. It is known that str does not conform to the Container protocol due to its incompatible signature for __contains__ method.
  • isinstance(foo, Sequence), etc. will narrow foo to str | Sequence[Any], etc. to be consistent with runtime behavior. That implies in order to iterate through foo, one must check isinstance(foo, Sequence) and not isinstance(foo, str).

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@michaelm-openai
Copy link
Contributor Author

I think the apprise diff is expected given that we added a new overload. The full diagnostic is:

apprise/config/base.py:1509: error: No overload variant of "iter" matches argument type "None"  [call-overload]
apprise/config/base.py:1509: note: Possible overload variants:
apprise/config/base.py:1509: note:     def [_SupportsNextT_co: SupportsNext[Any]] iter(SupportsIter[_SupportsNextT_co], /) -> _SupportsNextT_co
apprise/config/base.py:1509: note:     def iter(str, /) -> Iterator[str]
apprise/config/base.py:1509: note:     def [_T] iter(_GetItemIterable[_T], /) -> Iterator[_T]
apprise/config/base.py:1509: note:     def [_T] iter(Callable[[], _T | None], None, /) -> Iterator[_T]
apprise/config/base.py:1509: note:     def [_T] iter(Callable[[], _T], object, /) -> Iterator[_T]

@github-actions

This comment has been minimized.

@michaelm-openai michaelm-openai force-pushed the michaelm/disallow-str-iteration branch from 9170fb1 to 473a4a1 Compare January 15, 2026 04:14
@github-actions

This comment has been minimized.

@michaelm-openai michaelm-openai force-pushed the michaelm/disallow-str-iteration branch 2 times, most recently from 09762a7 to 41bb4d3 Compare January 15, 2026 09:00
@github-actions

This comment has been minimized.

@michaelm-openai michaelm-openai force-pushed the michaelm/disallow-str-iteration branch from 8edc2d8 to 2591e4b Compare January 19, 2026 10:05
@michaelm-openai michaelm-openai force-pushed the michaelm/disallow-str-iteration branch from 60e8382 to 7ca80af Compare January 19, 2026 10:07
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

apprise (https://github.com/caronc/apprise)
+ apprise/config/base.py:1509: note:     def iter(str, /) -> Iterator[str]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow mypy to flag str matching against Sequence[str] as an error

2 participants