Skip to content

Add a "Patterns" chapter #465

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

Closed
matrixise opened this issue Feb 20, 2019 · 5 comments
Closed

Add a "Patterns" chapter #465

matrixise opened this issue Feb 20, 2019 · 5 comments

Comments

@matrixise
Copy link
Member

Yesterday, I have fixed an issue in bpo and this issue was for the support of os.PathLike in FileCookieJar. Since the introduction of os.PathLike and __fspath__, we continue to convert some parts of code to be os.PathLike compliant and I think there is a pattern for that.

Maybe we could create a page "Patterns" with some examples.

For example (but need to be tested and approved)

How to support a os.PathLike object?

def __init__(self, filename):
    try:
        filename = os.fspath(filename)
    except TypeError:
        raise ValueError("filename must be a string-like or path-like object")
@Mariatta
Copy link
Member

GitMate.io thinks possibly related issues are python/core-workflow#189 (Add CONTRIBUTING.md), #3 (Add Travis support), #172 (Add PDF build), #136 (Add a chapter for introducing common function / class' corresponding source file), and python/core-workflow#32 (Add the mention bot?).

@ncoghlan
Copy link
Contributor

ncoghlan commented Feb 20, 2019

Why are we converting an accurate TypeError to an incorrect ValueError? (If the passed in object doesn't adhere to what os.fspath supports, changing the value passed in won't help - you have to pass in an argument of a different type)

@matrixise
Copy link
Member Author

@ncoghlan good catch

my example comes from cookiejar where there was a check and if there was an exception this one was catched and re-raised as a ValueError

I could fix it in cookiejar but I don't want to break the backward-compatiblity, or maybe I could document it in the whatsnew/38.html

I am going to fix my PR with your recommendation in CPython: https://github.com/python/cpython/pull/11945/files#diff-e85eca61cec5281c45f14cd6819bf548L1766

Thank you

@matrixise
Copy link
Member Author

Ok I have fixed my PR python/cpython#11945

Thank you

@brettcannon
Copy link
Member

I think this is out of scope for the devguide. Patterns like this are a general thing for the wider community and should be covered elsewhere, e.g. blog posts or the documentation.

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

4 participants