Skip to content

Conversation

@bxngyn
Copy link

@bxngyn bxngyn commented Jul 15, 2025

#358

put check50.configure(truncate_len=numberhere) at top of pset's check __init__.py file. if configuration given, standard truncation is used where the string will just splice after numberhere # of chars. if no configuration given, automatic dynamic truncation of 10 chars is used.

see ex here: https://github.com/cs50/problems/blob/test-truncation/caesar/__init__.py

@rongxin-liu rongxin-liu changed the title Patch invis chars Make Truncating Configurable Jul 15, 2025
@rongxin-liu rongxin-liu added the 4.x Issues relating to check50 4.x label Jul 15, 2025
@rongxin-liu rongxin-liu added this to the 4.0.0 milestone Jul 15, 2025
@ivanharvard
Copy link

ivanharvard commented Jul 31, 2025

I changed the way the variables in the configuration are set. To modify the truncation length, use

import check50
check50.config.set_truncate_len(<value>)

anywhere within your file, where <value> is the actual length you wish to enter.

I also modified it so that the config for check50 is very easily extensible for developers. Simply add a new variable to the __init__ of the Config class in config.py, and a new setter function will be automatically generated based on the variable name. You can optionally add validators into the _validators dictionary for any variable you wish, with optional help messages.

The name of the function depends on the type of the default value you assign. If that default value is a bool, then the function will be of the form toggle_<variable name>(). Otherwise, it will be of the form set_<variable name>(<value>).

For instance, to disable the dynamic truncation, use

import check50
check50.config.toggle_dynamic_truncate()

anywhere within your file.

All configuration setter functions will be accessible under the check50.config namespace.

@ivanharvard
Copy link

ivanharvard commented Jul 31, 2025

For readability's sake, I've removed toggle_ functions. Now, users must explicitly set the variable's value, even if the default value is a boolean, and developers who extend the Config class are recommended to implement validators for their boolean variables.

For instance, to disable the dynamic truncation, use

import check50
check50.config.set_dynamic_truncate(False)

@rongxin-liu rongxin-liu requested a review from Copilot July 31, 2025 21:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces configurable truncation for check50 output formatting. Users can now set a custom truncation length and choose between dynamic or standard truncation modes through a configuration system.

  • Adds a new Config class with validation and dynamic setter generation
  • Modifies the truncation logic to respect configuration settings
  • Exposes the config object through the public API

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
check50/config.py Implements the Config class with truncation settings and dynamic setter generation
check50/_api.py Updates _truncate function to use configuration values instead of hardcoded parameters
check50/init.py Exports the config object to make it accessible to users
Comments suppressed due to low confidence (1)

check50/config.py:17

  • [nitpick] The variable name 'dynamic_truncate' is unclear. Based on the usage, it appears to control whether dynamic truncation is enabled. Consider renaming to 'use_dynamic_truncate' or 'enable_dynamic_truncate' for clarity.
        self.dynamic_truncate = True

Copy link
Author

@bxngyn bxngyn left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@rongxin-liu rongxin-liu left a comment

Choose a reason for hiding this comment

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

Fancy!

@bxngyn bxngyn merged commit 6e56ab6 into 4.0.0-dev Jul 31, 2025
1 check passed
@bxngyn bxngyn deleted the patch-invis-chars branch July 31, 2025 21:21
This was linked to issues Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.x Issues relating to check50 4.x enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make truncating configurable truncate values that are too big

4 participants