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

Lack of type checks in pkgutil.walk_packages and friends #68932

Closed
sleepycal mannequin opened this issue Jul 28, 2015 · 8 comments
Closed

Lack of type checks in pkgutil.walk_packages and friends #68932

sleepycal mannequin opened this issue Jul 28, 2015 · 8 comments
Labels
3.7 stdlib type-bug

Comments

@sleepycal
Copy link
Mannequin

@sleepycal sleepycal mannequin commented Jul 28, 2015

BPO 24744
Nosy @bitdancer, @CuriousLearner
PRs
  • #1926
  • 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 = <Date 2017-06-13.17:12:32.797>
    created_at = <Date 2015-07-28.16:11:28.031>
    labels = ['3.7', 'type-bug', 'library']
    title = 'Lack of type checks in pkgutil.walk_packages and friends'
    updated_at = <Date 2017-06-13.17:12:32.796>
    user = 'https://bugs.python.org/sleepycal'

    bugs.python.org fields:

    activity = <Date 2017-06-13.17:12:32.796>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-06-13.17:12:32.797>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2015-07-28.16:11:28.031>
    creator = 'sleepycal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 24744
    keywords = []
    message_count = 8.0
    messages = ['247529', '247531', '295070', '295076', '295125', '295260', '295941', '295942']
    nosy_count = 3.0
    nosy_names = ['r.david.murray', 'sleepycal', 'CuriousLearner']
    pr_nums = ['1926']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24744'
    versions = ['Python 3.7']

    @sleepycal
    Copy link
    Mannequin Author

    @sleepycal sleepycal mannequin commented Jul 28, 2015

    The documentation states that pkgutil.walk_packages() path must be None or a list of paths [1]. After passing in a string, the result was a blank list rather than a type error or automatic conversion to a list.

    If this method is documented that it must only accept a list or None, then there should surely be type checks to this effect? This was a bit of a gotcha that left me head scratching for 30 minutes (after not realising it only took a list, not an str, which in itself seems a bit odd)

    @sleepycal sleepycal mannequin added the interpreter-core label Jul 28, 2015
    @bitdancer
    Copy link
    Member

    @bitdancer bitdancer commented Jul 28, 2015

    Well, normally no, we don't use type checks. On the other hand, having it produce an incorrect result rather than an error of *some* sort is not so good (the problem is that it is ultimately calling map(func, path), and map happily iterates the string applying func to each character in turn), so in this case I think it is worth the explicit check for string.

    @CuriousLearner
    Copy link
    Member

    @CuriousLearner CuriousLearner commented Jun 3, 2017

    Hi r.david.murray,

    What error do you think should be raised in this case, when path is an instance of str?

    I'll issue a PR once I know what end results are expected.

    @bitdancer
    Copy link
    Member

    @bitdancer bitdancer commented Jun 3, 2017

    As I mentioned on the PR I think it should be a ValueError, and that the PR also needs tests.

    @CuriousLearner
    Copy link
    Member

    @CuriousLearner CuriousLearner commented Jun 4, 2017

    I've updated the PR with required changes along with the test. Please have a look and let me know if any changes are needed.

    @bitdancer
    Copy link
    Member

    @bitdancer bitdancer commented Jun 6, 2017

    In thinking about merging this, I realize something I should have thought about earlier: we are proposing to raise an error where none was previously raised. Now, any code that would hit this would be broken, but nonetheless, by our backward compatibility policy we should do this only in 3.7, and we should add a note to the porting section of What's New. And the PR needs a news entry.

    @bitdancer bitdancer added stdlib 3.7 type-bug and removed interpreter-core labels Jun 6, 2017
    @bitdancer
    Copy link
    Member

    @bitdancer bitdancer commented Jun 13, 2017

    New changeset b9c3da5 by R. David Murray (Sanyam Khurana) in branch 'master':
    bpo-24744: Raises error in pkgutil.walk_packages if path is str (bpo-1926)
    b9c3da5

    @bitdancer
    Copy link
    Member

    @bitdancer bitdancer commented Jun 13, 2017

    Thanks, Sanyam.

    @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.7 stdlib type-bug
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants