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

textwrap.wrap: add control for fonts with different character widths #56708

Open
parent5446 mannequin opened this issue Jul 5, 2011 · 6 comments
Open

textwrap.wrap: add control for fonts with different character widths #56708

parent5446 mannequin opened this issue Jul 5, 2011 · 6 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@parent5446
Copy link
Mannequin

parent5446 mannequin commented Jul 5, 2011

BPO 12499
Nosy @birkenfeld, @amauryfa, @merwok, @serhiy-storchaka, @xi
PRs
  • bpo-12499: support custom len function in textwrap.wrap #28136
  • Files
  • textwrap.py-widthfunction-2011-07-04_22-57-49_r71219+.diff: Addition of custom width function to textwrap.py.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-07-05.03:03:24.379>
    labels = ['type-feature', 'library', '3.11']
    title = 'textwrap.wrap: add control for fonts with different character widths'
    updated_at = <Date 2021-09-03.18:32:07.776>
    user = 'https://bugs.python.org/parent5446'

    bugs.python.org fields:

    activity = <Date 2021-09-03.18:32:07.776>
    actor = 'eric.araujo'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2011-07-05.03:03:24.379>
    creator = 'parent5446'
    dependencies = []
    files = ['22574']
    hgrepos = []
    issue_num = 12499
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['139828', '139829', '139881', '139894', '231092', '401011']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'amaury.forgeotdarc', 'eric.araujo', 'parent5446', 'serhiy.storchaka', 'xi2']
    pr_nums = ['28136']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12499'
    versions = ['Python 3.11']

    @parent5446
    Copy link
    Mannequin Author

    parent5446 mannequin commented Jul 5, 2011

    Originally from http://bugs.python.org/issue12485 but separated.

    The textwrap modules uses len to determine the length of text, but in many (if not most) fonts, the width of a character differs depending on the letter, so it would be useful to have an option to pass a custom function that returns the width of a given string of text.

    @parent5446 parent5446 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jul 5, 2011
    @amauryfa
    Copy link
    Member

    amauryfa commented Jul 5, 2011

    About the patch: the function should not be passed to the constructor, it could be a regular method that can be overridden in subclasses.

    @merwok
    Copy link
    Member

    merwok commented Jul 5, 2011

    Amaury, do you think it’s more common to subclass TextWrapper than just instantiate it? I find the proposed API (an argument to __init__) very intuitive.

    @parent5446
    Copy link
    Mannequin Author

    parent5446 mannequin commented Jul 5, 2011

    Normally I would have just added it as a function to be overloaded, but because of the nature of the textwrap.wrap function (all kwargs are passed to the TextWrapper constructor) I thought it made a lot more sense to keep it as an argument to __init__.

    @serhiy-storchaka
    Copy link
    Member

    Both approaches can be combined. It could be a regular overridable method, and it could be overridded for an instance if corresponding argument is specified. See the default method and parameter of JSON encoder.

    I slightly hesitate about the name. Is "width_func" the best of names?

    @merwok
    Copy link
    Member

    merwok commented Sep 3, 2021

    A PR was opened for this. text_len is used as param/attribute name.

    @merwok merwok added the 3.11 only security fixes label Sep 3, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants