-
Example (link to Mypy playground): from typing_extensions import Generic, TypeVar
T = TypeVar("T", default=int)
class ListWrapper(Generic[T]):
def __init__(self, input_list: list[T]) -> None:
self.input_list = input_list
def print_wrapper(wrapper_instance: ListWrapper) -> None: # main.py:10: error: Missing type parameters for generic type "ListWrapper" [type-arg]
print(wrapper_instance.input_list)
x = ListWrapper([1, 2, 3])
reveal_type(x) # main.py:14: note: Revealed type is "__main__.ListWrapper[builtins.int]"
print_wrapper(x) I suspect I am just misunderstanding the way this works. I had the expectation that I would no longer need to specialize |
Beta Was this translation helpful? Give feedback.
Answered by
Gobot1234
Nov 30, 2023
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
gandhis1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bug in mypy's implementation (pyright's works fine here https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmB9ApgDxllAZyTCKiQgTBBigHECsQkBjAGigBVEsA1AQxABYAFCjOUALxceAkAAoARJ0UcAJlmD8ArgBsYk1DACUo0S139ChKABkkhGAHUQ-BAibyGKJqwDanAC6xgBcolARUBrAUBgYqEgwcfKEWLrAHKgI2km6DjAhUHmOAcFQALQAfFAAcqRYYSKRzVCp6QB0WTkYxbTSXbn5ZmIi0VAIzChJAO6u7p6zbh4g8UQw-CgsDXb5LktMxhXVdT6FUADEUBD8qO0IcCEAjAAMhUzgIIUAsg7E6LA8caCfgQLD4EA2YDUKBoRjMFgAjxQRT2Rx7eYgRQRPzwDzlQRoQLhSITIzyRYY1aODZbToobKDRymEY4KQ7NFzZbyPyPDgAJg4AGZgqIQFgAG5Yfi6DC4rDyHCHC5XG4oO4PR4AFkKKDA+EKACUJVLdFg1IisOQbIo4tdUHF2qjnJymH4AEbaJD6VCEOkwQKKUSkqYYClcxVAA). It should work according to the PEP.