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
Python 3.11 StrEnum error when member is named "title" #14494
Currently when running mypy==0.991 on a Python 3.11 file that's using StrEnum, it errors unexpectedly on an specific named member on my code. In this case, the member only needed to be named title to get an Incompatible types in assignment error.
I realize python 3.11 support gh-12840 is still ongoing, but I thought I should report it to help others who might encounter this.
It might also be worth noting that it happens in older Python versions (tested on 3.10) when using strenum backport.
To Reproduce
fromenumimportStrEnumclassTheBug0(StrEnum):
lorem="foo"ipsum="ipsum"title="bug0"# Bug because left side is named "title"?classTheBug1(StrEnum):
lorem="foo"title="bug1"# Bug because left side is named "title"?ipsum="bar"classTheBug2(StrEnum):
title="bug2"# Bug because left side is named "title"?lorem="foo"ipsum="bar"classNoBug(StrEnum):
lorem="foo"ipsum="bar"
main.py:7: error: Incompatible types in assignment (expression has type"str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:12: error: Incompatible types in assignment (expression has type"str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:17: error: Incompatible types in assignment (expression has type"str", base class "str" defined the type as "Callable[[str], str]") [assignment]
Found 3 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 0.991
Mypy command-line flags: mypy main.py
Mypy configuration options from mypy.ini (and other config files): None
main.py:5: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:6: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:7: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, SupportsIndex, str], str]") [assignment]
main.py:8: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, Optional[SupportsIndex], Optional[SupportsIndex]], int]") [assignment]
main.py:9: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, str], bytes]") [assignment]
main.py:10: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Union[str, Tuple[str, ...]], Optional[SupportsIndex], Optional[SupportsIndex]], bool]") [assignment]
main.py:11: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, SupportsIndex], str]") [assignment]
main.py:12: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, Optional[SupportsIndex], Optional[SupportsIndex]], int]") [assignment]
main.py:13: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, VarArg(object), KwArg(object)], str]") [assignment]
main.py:14: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, _FormatMapMapping], str]") [assignment]
main.py:15: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, Optional[SupportsIndex], Optional[SupportsIndex]], int]") [assignment]
main.py:16: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:17: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:18: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:19: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:20: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:21: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:22: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:23: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:24: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:25: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:26: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:27: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], bool]") [assignment]
main.py:28: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Iterable[str]], str]") [assignment]
main.py:29: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, SupportsIndex, str], str]") [assignment]
main.py:30: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:31: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Optional[str]], str]") [assignment]
main.py:32: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as overloaded function) [assignment]
main.py:33: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str], Tuple[str, str, str]]") [assignment]
main.py:34: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str], str]") [assignment]
main.py:35: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str], str]") [assignment]
main.py:36: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, str, SupportsIndex], str]") [assignment]
main.py:37: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, Optional[SupportsIndex], Optional[SupportsIndex]], int]") [assignment]
main.py:38: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, Optional[SupportsIndex], Optional[SupportsIndex]], int]") [assignment]
main.py:39: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, SupportsIndex, str], str]") [assignment]
main.py:40: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str], Tuple[str, str, str]]") [assignment]
main.py:41: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Optional[str], SupportsIndex], List[str]]") [assignment]
main.py:42: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Optional[str]], str]") [assignment]
main.py:43: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Optional[str], SupportsIndex], List[str]]") [assignment]
main.py:44: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, bool], List[str]]") [assignment]
main.py:45: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Union[str, Tuple[str, ...]], Optional[SupportsIndex], Optional[SupportsIndex]], bool]") [assignment]
main.py:46: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, Optional[str]], str]") [assignment]
main.py:47: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:48: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:49: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, _TranslateTable], str]") [assignment]
main.py:50: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str], str]") [assignment]
main.py:51: error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, SupportsIndex], str]") [assignment]
Found 47 errors in 1 file (checked 1 source file)
Activity
ngnpope commentedon Jan 23, 2023
Interesting... This is because
enum.StrEnumis a subclass ofstr, so thetitlemember ends up shadowingstr.title().In fact, the same can be observed when trying to use member names that shadow other methods of
str:This chucks out the following:
https://mypy-play.net/?mypy=latest&python=3.11&gist=d21b0840b2caefcb83142ca1f0d0b7ca
JelleZijlstra commentedon Jan 23, 2023
This error is correct. You have an incompatible override, which creates unsound code.
Consider:
ngnpope commentedon Jan 23, 2023
Probably something that should be mentioned under the limitations in the documentation, if anyone cares enough to write a patch... 🤷🏻
samypr100 commentedon Apr 19, 2023
Note, this behavior should now fixed upstream due to python/cpython#103600
Add remove_private_as option on bgp neighbors