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

Support accessing reserved word resource properties via attribute #1178

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

anniel-stripe
Copy link
Contributor

Currently, accessing a property with the same name as a Python reserved word as a resource attribute does not work. The only known case of this is for the country code is on country_options of a Tax Registration resource.

Accessing the property as an object attribute will result in a syntax error:

>>> taxreg.country_options.is
  File "<stdin>", line 1
    reg.country_options.is
                        ^^
SyntaxError: invalid syntax

This means the nested property can only be accessed via dictionary key: reg.country_options["is"].

_field_remappings allows reserved word properties to be accessed as an attribute via the property name + _, like so:

>>> taxreg.country_options.is_
<Is at 0x104b5ef70> JSON: {
  "type": "standard"
}

The _field_remappings property is already generated in stripe/tax/_registration.py.

@anniel-stripe anniel-stripe changed the title Support reserved word resource properties Support accessing reserved word resource properties via attribute getter Dec 18, 2023
@anniel-stripe anniel-stripe changed the title Support accessing reserved word resource properties via attribute getter Support accessing reserved word resource properties via attribute Dec 18, 2023
@anniel-stripe anniel-stripe merged commit 3a34544 into master Dec 18, 2023
15 checks passed
@xavdid-stripe xavdid-stripe deleted the anniel-field-remappings branch May 10, 2024 03:27
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

Successfully merging this pull request may close these issues.

None yet

2 participants