RequestSequence is difficult to use on Python 3

Open
#191 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
api, testing-qa

Research direction

The issue names RequestSequence, HasHeaders, request tuples, and response tuples; start by locating those entry points and comparing their current type handling. The scope is not singular: settle whether the change covers rejecting or coercing str and bytes, header consistency, a builder API, or some combination. Done should mean the selected behavior is specified and consistently applied.

Written by the indexing model from the issue text.

Description

RequestSequence is very picky about types of arguments, but lacks any checking or coercion. For example, in the request tuple:

  • b'get' vs. 'get'—the former is required
  • b'get' vs. 'GET'—the former is required
  • The URL is str, but everything else must be bytes

If you pass the wrong type, the request sequence will not ever match. I'd say we should blacklist str where bytes is required and vice-versa. (Blacklist rather than whitelist because the ability to pass fuzzy matchers like HasHeaders is useful.)

In the response tuple:

  • Headers must be a dict of strings, as noted in #123, which is inconsistent with HasHeaders. HasHeaders requires lists of strings.

And generally speaking, writing out these tuples is easy to botch. Perhaps we should add a builder API to make it easier?

Dominant language
Python
Stars
603
Forks
140
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from twisted/treq

All issues in twisted/treq

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.