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

Potential bug in Generics section of Python book #187

Open
turbolent opened this issue Nov 24, 2024 · 0 comments
Open

Potential bug in Generics section of Python book #187

turbolent opened this issue Nov 24, 2024 · 0 comments

Comments

@turbolent
Copy link

turbolent commented Nov 24, 2024

There might be a bug in the TypeCheckLgeneric.

AllType is a Type, and its type parameters are strings:

params: list[str]

GenericVar is a Type, referencing a type parameter, a string:

id: str

In the substitute_type function, the keys of the var_map dictionary seem to be type parameters names (strings, str), and the values seem to be types (Type).

However, in match_types function, in the AllType case, the var_map passed to substitute_type seems to construct a dictionary mapping type parameter names (str) to type parameter names (str), not types:

rename = {ap:p for (ap,p) in zip(arg_ps, ps)}
new_arg_ty = self.substitute_type(arg_ty, rename)

Shouldn't the values be wrapped in GenericVar, i.e.

rename = {ap: GenericVar(p) for (ap,p) in zip(arg_ps, ps)}

That is also what is done in the check_type_equal function, in the AllTypes case:

rename = {p2: GenericVar(p1) for (p1,p2) in zip(ps1,ps2)}

Great work and thank you for the fantastic book!

@turbolent turbolent changed the title Questions for and potential issue in Generics section of Python book Potential bug in Generics section of Python book Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant