Skip to content

braintree: Use Final for string constants#11680

Merged
srittau merged 7 commits into
python:mainfrom
Avasam:braintree-string-constants
Apr 1, 2024
Merged

braintree: Use Final for string constants#11680
srittau merged 7 commits into
python:mainfrom
Avasam:braintree-string-constants

Conversation

@Avasam
Copy link
Copy Markdown
Collaborator

@Avasam Avasam commented Mar 31, 2024

Based on #11678 to avoid conflicts, so please merge that first

As title says. There's a bunch of classes that braintree uses like string Enums

There's a few strings that were just a bit too long, triggering Y053. although I'm not sure if, given the context they're in, it makes more sense to noqa. Take a look at this commit for comparison: cea228d

@github-actions

This comment has been minimized.

@srittau
Copy link
Copy Markdown
Collaborator

srittau commented Apr 1, 2024

Conflicts now (as expected).

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from one personal and completely optional style remark below.

Comment on lines +7 to +9
AmEx: Final = "Apple Pay - American Express"
MasterCard: Final = "Apple Pay - MasterCard"
Visa: Final = "Apple Pay - Visa"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion: These user facing strings with no further meaning to the computer should just be Final[str] = ..., while something like GatewayRejected: Final = "gateway_rejected" below makes sense.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just a personal opinion: I feel it's easier to indiscriminately copy&paste from source, w/o having to think too much about what arbitrarily counts as an identifier vs a human readable string, which other contributors may not notice and follow in the same way.

There's an argument about the risk of the string changing, causing more churn, but I doubt these are likely to change without a major revision:

  • braintree_python won't even remove dead code without a major version bump
  • this card type, for example, is part of the result object for a transaction, it's likely users already highly depend on the value of this string for their transaction logs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 28fe4cc into python:main Apr 1, 2024
@Avasam Avasam deleted the braintree-string-constants branch April 1, 2024 15:19
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.

2 participants