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

Fix CacheControl issues #2882

Merged
merged 1 commit into from
Jul 14, 2024
Merged

Conversation

RazerM
Copy link
Contributor

@RazerM RazerM commented Apr 19, 2024

  • no-transform is a boolean, rather than always None.
  • min-fresh is an int, returning None if empty rather than *.
  • Fix some property types:
    • Bool properties never return None.
    • Non-bool types return str not bool.
    • max-stale can return "*"
    • Request properties are immutable
    • Fix some response setter types
  • Add must-understand response property.

Fixes #2881

@RazerM RazerM force-pushed the feature/cache-control-issues branch from 333ad19 to 8bff7d0 Compare April 19, 2024 11:06
@davidism davidism modified the milestones: 3.0.3, 3.1.0 May 4, 2024
Cache-Control no-transform directive is a boolean

no-transform has no arguments as a request or response directive (RFC
9111). Prior to this fix, cc.no_transform would return None whether the
directive is present or not.

Cache-Control min-fresh directive requires argument

The type for this property is `int | None`, so getting `"*"` for a
malformed directive is surprising. I think dropping the empty value here
is better than fixing the type.

Fix CacheControl getter type stubs

- cache_control_property with type=bool never return None
- some non-bool types were marked as returning bool instead of str
- max_stale can return "*" in addition to int or None

Reflect immutability of RequestCacheControl in type stubs

Fix CacheControl setter type stubs

mypy doesn't use the type of setters as of 1.9.0 (see python/mypy#3004),
but I think it's still good to have these be accurate (maybe the other
type checkers work better here).

mypy's recommendation is to use `# type: ignore` comments if setter
types don't match getters, which you see when setting no_cache to True.

Support must-understand response directive
@davidism davidism force-pushed the feature/cache-control-issues branch from 9e043b4 to b28001e Compare July 12, 2024 15:47
@davidism davidism merged commit 9e050f7 into pallets:main Jul 14, 2024
12 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Several issues with CacheControl types
2 participants