Skip to content

ch21 cleanup, f-strings, and pathlib #4

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 1 commit into from
Feb 14, 2021
Merged

Conversation

eumiro
Copy link
Contributor

@eumiro eumiro commented Feb 13, 2021

Some cleanup of the chapter 21, usage of f-strings, and pathlib.Path for dir/file operations. Alphabetic sorting of imports and some reformatting.

There's one point that is not the topic of this chapter, but the supplementary tests in argparse could be put directly into add_argument, but then the number of lines would explode:

    parser.add_argument(
        '-l', '--limit', metavar='N', type=int, help='limit to N first codes',
        default=sys.maxsize)
    …
    if args.limit < 1:
        print('*** Usage error: --limit N must be >= 1')
        parser.print_usage()
        sys.exit(1)

could be changed to:

    def validate_limit(value):
        try:
            res = int(val)
            if res < 1:
                raise ValueError()
        except ValueError:
            raise argparse.ArgumentTypeError("must be integer >= 1")
        else:
            return res
    parser.add_argument(
        '-l', '--limit', metavar='N', type=validate_limit, help='limit to N first codes',
        default=sys.maxsize)

But this was just to see how it works, so let's keep the argparse how it is.

@ramalho ramalho merged commit 584a7f2 into fluentpython:master Feb 14, 2021
@ramalho
Copy link
Member

ramalho commented Feb 14, 2021

Thank you very much, @eumiro!

@eumiro eumiro deleted the ch21 branch February 16, 2021 19:01
rct pushed a commit to rct/book-fluent-python-2e-code that referenced this pull request Feb 5, 2024
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