You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Perhaps declare a __new__ instead of an __init__ for str and other similar types #4514
A short test indicates to me that str has both __init__() and __new__(), so we should define both in typeshed. (After checking with the implementation, of course.)
FWIW, I just checked the following example from #1464:
fromenumimportEnumfromtypingimportTYPE_CHECKINGifnotTYPE_CHECKING:
reveal_type=printclassI(int, Enum):
a=1reveal_type(I['a']) # E: Revealed type is '__main__.I'classS(str, Enum):
a='1'reveal_type(S['a']) # E: Revealed type is '__main__.S'classF(float, Enum):
a=1.0reveal_type(F['a']) # E: Revealed type is '__main__.F'
It still works when I add the following definitions to str:
Activity
srittau commentedon Sep 6, 2020
A short test indicates to me that
strhas both__init__()and__new__(), so we should define both in typeshed. (After checking with the implementation, of course.)Edit:
srittau commentedon Sep 6, 2020
@JelleZijlstra pointed to #1352 and #1464, where this was (unsuccessfully) tried before.
srittau commentedon Sep 6, 2020
FWIW, I just checked the following example from #1464:
It still works when I add the following definitions to
str:(No guarantee that these are the correct definitions for
str, though.) This makes me hopeful that the original underlying problem is solved.Use __new__ instead of __init__ for some builtin classes
Use __new__ instead of __init__ for some builtin classes (#4555)