Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyType permits usage of two different types for one TypeVar. #1557

Open
Frang84 opened this issue Dec 28, 2023 · 1 comment
Open

PyType permits usage of two different types for one TypeVar. #1557

Frang84 opened this issue Dec 28, 2023 · 1 comment
Labels
bug cat: generics Generic, TypeVar, containers

Comments

@Frang84
Copy link

Frang84 commented Dec 28, 2023

Pytype permits one typeVar (T) for being a list of strings and list of integers.

T = TypeVar("T")
 
   
def functionTab(input_list: List[T], addend: T) -> List[T]: 
  output_list: List[T] = []
  for i in input_list:
    output_list.append(i + addend)
  return output_list
 
 
 
test_list :List[List[int]] = [[1,2,3], [4,5,6]]
result = functionTab(test_list, ["abcd"])
 

OUTPUT:
Success: no errors found

@rchen152 rchen152 added bug cat: generics Generic, TypeVar, containers labels Jan 3, 2024
@rchen152
Copy link
Contributor

rchen152 commented Jan 8, 2024

Also happens with Sequence and Iterable:

T = TypeVar("T")
def functionTab(first: T, second: T) -> T : 
  resultList = []
  for i in first:
    resultList.append(i)
  for i in second:
    resultList.append(i)
  return resultList  

list1 : Sequence[str] = ["dog", "cat"]
list2 : Sequence[int] = [1,2,3]


functionTab(list1, list2)
def functionTab(first: T, second: T) -> T : 
  resultList = []
  for i in first:
    resultList.append(i)
  for i in second:
    resultList.append(i)
  return resultList  

list1 : Iterable[int] = [1,2,3]
list2 : Iterable[str] = ["dog", "cat"]

functionTab(list1, list2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: generics Generic, TypeVar, containers
Projects
None yet
Development

No branches or pull requests

2 participants