Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 1 | 2 |
invalid-assignment |
0 | 0 | 1 |
| Total | 0 | 1 | 3 |
Raw diff:
dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/propagation/_database_monitoring.py:136:13 error[invalid-assignment] Invalid subscript assignment with key of type `Literal["ddsh"]` and value of type `LiteralString` on object of type `dict[Literal["ddps", "dde", "ddpv", "dddbs"], Unknown | str]`
+ ddtrace/propagation/_database_monitoring.py:136:13 error[invalid-assignment] Invalid subscript assignment with key of type `Literal["ddsh"]` and value of type `str` on object of type `dict[Literal["ddps", "dde", "ddpv", "dddbs"], Unknown | str]`
mitmproxy (https://github.com/mitmproxy/mitmproxy)
- mitmproxy/io/tnetstring.py:191:20 error[invalid-argument-type] Argument to class `str` is incorrect: Expected `bytes | bytearray`, found `memoryview[int]`
pip (https://github.com/pypa/pip)
- src/pip/_vendor/requests/models.py:937:41 error[invalid-argument-type] Argument to class `str` is incorrect: Expected `str`, found `Unknown | None`
+ src/pip/_vendor/requests/models.py:937:41 error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str`, found `Unknown | None`
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 `str`
+ sklearn/datasets/_lfw.py:469:60 error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Buffer`, found `str`
AlexWaygood
left a comment
There was a problem hiding this comment.
Yeah, agreed, this special-casing just isn't worth it
There was a problem hiding this comment.
I think we could have also fixed it by implementing this TODO? (which I couldn't implement when I added this code here because we didn't have support for protocols back then, I believe). I'm not opposed to removing this special handling, but it does lead to some minor regressions (e.g. being able to infer str(<literal>) as Literal[<literal>]). On the other hand, having less code is always good. I'm fine either way.
There was a problem hiding this comment.
Yes, that's right -- fixing that TODO and matching our special-cased constructor signature to the typeshed one would have been the other way to fix this. I felt that if we think inferring str("foo") as Literal["foo"] is important, it would be better to implement this via an additional overload in typeshed, rather than by maintaining our own hardcoded copy of the str constructor overloads from typeshed.
There was a problem hiding this comment.
Now I'm curious: how would you model this by adding an additional overload?
There was a problem hiding this comment.
I admit I didn't try this out (or even think through it in depth), since I suspect that this particular precision is not important, but it seemed to me that an overload like this would do it?
@overload
def __new__[T: LiteralString](cls, object: T) -> T: ...
Summary
Fixes astral-sh/ty#3243
Remove our hardcoded handling of the
strconstructor, in favor of just using the typeshed definition.A side effect here is that we lose our precise inference of
str("foo")asLiteral["foo"]instead ofstr. This is behavior that no other type checker has, and really the right way to provide it would be via an additional overload ofstr.__new__in typeshed, rather than via hardcoding. We could preserve this behavior in this PR, but it involves hardcodingKnownClass::Strhandling deep inside the call-constructor code, and it seems preferable to avoid that.Test Plan
Added an mdtest, adjusted mdtest expectations.