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

Browser enums #62

Merged
merged 25 commits into from
Jan 5, 2024
Merged

Browser enums #62

merged 25 commits into from
Jan 5, 2024

Conversation

n8henrie
Copy link
Owner

Enums seem like a more correct way to provide discrete browser variants, and since they're easily available in Python for many versions now, I wanted to try passing an enum between functions internally instead of a string. This should provide much better type checking during development. As an additional advantage, any time it is necessary to accept a string from a user, this should be able to consolidate the parsing logic to a single location.

As StrEnum wasn't available until relatively late in the game, I used the "inherit from str, Enum" trick to allow easy comparisons:

>>> browser = BrowserType.CHROME
>>> browser == "chrome"
True
>>> browser == "chromE"
False

... though I don't think I'm leveraging this anywhere so a straight Enum with auto() variants would likely have been fine.

Added a deprecation warning for users passing in strings; it should be minimal friction to adapt code from browser="chrome" to browser=BrowserType("chrome") or browser=BrowserType.CHROME.

This is partly in preparation for adding a CLI tool, which I hope to embark on soon (#60), and I intend to finally add some proper logging as well (#46)

Would appreciate any thoughts if you have time @grandchild!

@n8henrie n8henrie changed the base branch from master to dev December 29, 2023 21:08
Copy link
Collaborator

@grandchild grandchild left a comment

Choose a reason for hiding this comment

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

A few seemingly unrelated commits with nixos things in the beginning, which I ignored. The rest looks good, but I only did a visual check. I didn't test the actual code (yet).

src/pycookiecheat/chrome.py Outdated Show resolved Hide resolved
src/pycookiecheat/chrome.py Outdated Show resolved Hide resolved
src/pycookiecheat/common.py Outdated Show resolved Hide resolved
tests/test_chrome.py Outdated Show resolved Hide resolved
@n8henrie
Copy link
Owner Author

n8henrie commented Jan 2, 2024

The rest looks good, but I only did a visual check. I didn't test the actual code (yet).

Thanks for looking

A few seemingly unrelated commits with nixos things in the beginning, which I ignored.

Yeah, old habits die hard.

@n8henrie n8henrie force-pushed the browser-enums branch 2 times, most recently from 827f967 to 91610ec Compare January 2, 2024 19:42
@n8henrie n8henrie merged commit 6403b16 into dev Jan 5, 2024
5 of 6 checks passed
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