Skip to content

Remove Python 3.8 support #1143

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

Merged
merged 5 commits into from
Nov 23, 2024
Merged

Remove Python 3.8 support #1143

merged 5 commits into from
Nov 23, 2024

Conversation

dbanty
Copy link
Collaborator

@dbanty dbanty commented Oct 20, 2024

Now that 3.8 is EoL, we can finally update to use 3.9's generic syntax!

@dbanty dbanty added the 🥚breaking This change breaks compatibility label Oct 20, 2024
@dbanty dbanty requested a review from eli-bl October 20, 2024 23:49
eli-bl
eli-bl previously approved these changes Oct 30, 2024
@dbanty dbanty merged commit 46dcdc5 into main Nov 23, 2024
19 checks passed
@dbanty dbanty deleted the drop-3.8 branch November 23, 2024 01:54
@johnthagen
Copy link
Collaborator

johnthagen commented Dec 11, 2024

@dbanty I was curious about the need to translate type into type_. Since type is a soft keyword, is this truly neccessary?

The type keyword is a new soft keyword. It is interpreted as a keyword only in this part of the grammar. In all other locations, it is assumed to be an identifier name.

I think the generated client would be easier to use if we kept fields named type as type? But perhaps I'm missing a bigger reason why this was done?


Edit: Oh, I see you are using the type built in. Are there reasons why the built in conflicts with a field named type (I haven't personally run into builtins conflicting like this before, especially since fields are typically accessed through self.type or cls.type).

If this really must be done, I'd personally advocate for using the old Type and keeping the fields named without underscores as they are in OpenAPI since the change to type_ affects all users of models that happen to use this name (which I suspect is somewhat common).

@eli-bl
Copy link
Collaborator

eli-bl commented Dec 11, 2024

@johnthagen I may be off base but I think the issue may not be specifically the presence of a class attribute with that name, but instead, the fact that the generated from_dict and to_dict methods end up creating a local variable with that name. I'm less clear on the exact circumstances in which that would cause a conflict; I know it's possible to reuse built-ins as variable names in some situations. But I know there have been other situations in this project where certain property names couldn't be used even when they were not built-ins, because something else in the scope had that name.

If that is the issue... I think everyone would agree that moving away from that local-variable-naming scheme would be helpful, but it's non-trivial due to the way template macros are being used (at least in the case of from_dict; I do have a solution for to_dict).

@dbanty
Copy link
Collaborator Author

dbanty commented Dec 11, 2024

@eli-bl is correct. The better solution would be to change the local variable naming, but it's a much bigger change.

Sticking with Type causes popular linters to scream, and I don't want to litter the generated code with exceptions.

type specifically causes so many conflicts in so many languages 😭. If you have control over the API I recommend kind

@johnthagen
Copy link
Collaborator

johnthagen commented Dec 11, 2024

I know it's possible to reuse built-ins as variable names in some situations

Yeah, Python supports shadowing at all levels, so locals will shadow built-ins within the scope they are declared. Shadowing typically makes this not a problem (otherwise lots of builtin names would need to be avoided).

A trivial example:

def main(a: type[int]) -> str:
    type = str(a)
    return type

print(main(int))

# prints: <class 'int'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🥚breaking This change breaks compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants